OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_FILTERS_IVF_PARSER_H_ | |
6 #define MEDIA_FILTERS_IVF_PARSER_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include "base/macros.h" | |
12 #include "media/base/media_export.h" | |
13 | |
14 namespace media { | |
15 | |
16 #pragma pack(push, 1) | |
17 struct MEDIA_EXPORT IvfFileHeader { | |
18 // Byte swap interger fields between native and (on disk) little endian. | |
19 void ByteSwap(); | |
20 | |
21 char signature[4]; // signature: 'DKIF' | |
henryhsu
2015/08/05 10:45:14
Can we have a constant to store DKIF?
Then we can
kcwu
2015/08/05 11:05:15
Done.
| |
22 uint16_t version; // version (should be 0) | |
23 uint16_t header_size; // size of header in bytes | |
24 uint32_t fourcc; // codec FourCC (e.g., 'VP80') | |
25 uint16_t width; // width in pixels | |
26 uint16_t height; // height in pixels | |
27 uint32_t timebase_denum; // timebase denumerator | |
28 uint32_t timebase_num; // timebase numerator. For example, if | |
29 // timebase_denum is 30 and timebase_num is 2, the | |
30 // unit of IvfFrameHeader.timestamp is 2/30 | |
31 // seconds. | |
32 uint32_t num_frames; // number of frames in file | |
33 uint32_t unused; // unused | |
34 }; | |
35 static_assert( | |
36 sizeof(IvfFileHeader) == 32, | |
37 "sizeof(IvfFileHeader) must be fixed since it will be used with file IO"); | |
38 | |
39 struct MEDIA_EXPORT IvfFrameHeader { | |
40 // Byte swap interger fields between native and (on disk) little endian. | |
41 void ByteSwap(); | |
42 | |
43 uint32_t frame_size; // Size of frame in bytes (not including the header) | |
44 uint64_t timestamp; // 64-bit presentation timestamp in unit timebase, | |
45 // which is defined in IvfFileHeader. | |
46 }; | |
47 static_assert( | |
48 sizeof(IvfFrameHeader) == 12, | |
49 "sizeof(IvfFrameHeader) must be fixed since it will be used with file IO"); | |
50 #pragma pack(pop) | |
51 | |
52 // IVF is a simple container format for video frame. It is used by libvpx to | |
53 // transport VP8 and VP9 bitstream. | |
54 class MEDIA_EXPORT IvfParser { | |
55 public: | |
56 IvfParser(); | |
57 | |
58 // Initializes the parser for IVF |stream| with size |size| and parses the | |
59 // file header. Returns true on success. | |
60 bool Initialize(const uint8_t* stream, | |
61 size_t size, | |
62 IvfFileHeader* file_header); | |
63 | |
64 // Parses the next frame. Returns true if the next frame is parsed without | |
65 // error. |frame_header| will be filled with the frame header and |payload| | |
66 // will point to frame payload (inside the |stream| buffer given to | |
67 // Initialize.) | |
68 bool ParseNextFrame(IvfFrameHeader* frame_header, const uint8_t** payload); | |
69 | |
70 private: | |
71 bool ParseFileHeader(IvfFileHeader* file_header); | |
72 | |
73 // Current reading position of input stream. | |
74 const uint8_t* ptr_; | |
75 | |
76 // The end position of input stream. | |
77 const uint8_t* end_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(IvfParser); | |
80 }; | |
81 | |
82 } // namespace media | |
83 | |
84 #endif // MEDIA_FILTERS_IVF_PARSER_H_ | |
OLD | NEW |