-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp4frag.hh
93 lines (84 loc) · 3.14 KB
/
mp4frag.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
*
* This is port of OpenHttpStreamer for win32
* copyright (c) 2011 [email protected]
*
* Originally:
* copyright (c) 2010 ZAO Inventos (inventos.ru)
* copyright (c) 2010 [email protected]
* copyright (c) 2010 [email protected]
* copyright (c) 2010 [email protected]
*
* This file is part of mp4frag.
*
* mp4grag is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* mp4frag is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifndef __mp4frag_hh__ac9d6258_0bd9_4b2f_b934_984389f48934
#define __mp4frag_hh__ac9d6258_0bd9_4b2f_b934_984389f48934
#include "mapping.hh"
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <string>
#include <streambuf>
#include <memory>
#include <stdint.h>
struct SampleEntry {
off_t _offset;
uint32_t _size;
uint32_t _timestamp;
uint32_t _composition_offset;
off_t offset() const { return _offset; }
uint32_t size() const { return _size; }
uint32_t timestamp() const { return _timestamp; }
uint32_t composition_offset() const { return _composition_offset & 0xFFFFFF; }
bool video() const { return _composition_offset & 0x80000000; }
bool keyframe() const { return _composition_offset & 0x40000000; }
SampleEntry(off_t o, uint32_t s, uint32_t ts, uint32_t comp, bool isvideo, bool iskey = false) {
_offset = o;
_size = s;
_timestamp = ts;
_composition_offset = comp & 0xFFFFFF;
if ( isvideo ) {
_composition_offset |= 0x80000000;
if ( iskey ) {
_composition_offset |= 0x40000000;
}
}
}
};
struct Fragment {
double _duration;
uint32_t _totalsize;
std::vector<SampleEntry> _samples;
Fragment() : _duration(0), _totalsize(0) {}
uint32_t timestamp_ms() const { return _samples[0].timestamp(); }
double duration() const { return _duration; }
};
struct Media {
std::string medianame;
unsigned width;
unsigned height;
double duration;
std::auto_ptr<Mapping> mapping;
std::vector<Fragment> fragments;
std::string videoextra, audioextra;
};
boost::shared_ptr<Media> make_fragments(const std::string& filename, unsigned fragment_duration);
void get_manifest(std::streambuf* sb, const std::vector< boost::shared_ptr<Media> >& medialist,
const std::string& video_id);
void serialize_fragment(std::streambuf *sb, const boost::shared_ptr<Media>& media, unsigned fragnum);
void serialize(std::streambuf *sbuf, const std::vector< boost::shared_ptr<Media> >& medialist);
void get_fragment(std::streambuf *out,
unsigned medianum, unsigned fragnum, const char *index, size_t indexsize,
const boost::function<boost::shared_ptr<Mapping> (const std::string&)>& mfactory
);
#endif