Update V8 to version 4.7.42.
[chromium-blink-merge.git] / media / filters / ivf_parser.h
blobfe234aac3b1aa6649dbcced714f3f8a306df8202
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.
5 #ifndef MEDIA_FILTERS_IVF_PARSER_H_
6 #define MEDIA_FILTERS_IVF_PARSER_H_
8 #include <stddef.h>
9 #include <stdint.h>
11 #include "base/macros.h"
12 #include "media/base/media_export.h"
14 namespace media {
16 const char kIvfHeaderSignature[] = "DKIF";
18 #pragma pack(push, 1)
19 struct MEDIA_EXPORT IvfFileHeader {
20 // Byte swap interger fields between native and (on disk) little endian.
21 void ByteSwap();
23 char signature[4]; // signature: 'DKIF'
24 uint16_t version; // version (should be 0)
25 uint16_t header_size; // size of header in bytes
26 uint32_t fourcc; // codec FourCC (e.g., 'VP80')
27 uint16_t width; // width in pixels
28 uint16_t height; // height in pixels
29 uint32_t timebase_denum; // timebase denumerator
30 uint32_t timebase_num; // timebase numerator. For example, if
31 // timebase_denum is 30 and timebase_num is 2, the
32 // unit of IvfFrameHeader.timestamp is 2/30
33 // seconds.
34 uint32_t num_frames; // number of frames in file
35 uint32_t unused; // unused
37 static_assert(
38 sizeof(IvfFileHeader) == 32,
39 "sizeof(IvfFileHeader) must be fixed since it will be used with file IO");
41 struct MEDIA_EXPORT IvfFrameHeader {
42 // Byte swap interger fields between native and (on disk) little endian.
43 void ByteSwap();
45 uint32_t frame_size; // Size of frame in bytes (not including the header)
46 uint64_t timestamp; // 64-bit presentation timestamp in unit timebase,
47 // which is defined in IvfFileHeader.
49 static_assert(
50 sizeof(IvfFrameHeader) == 12,
51 "sizeof(IvfFrameHeader) must be fixed since it will be used with file IO");
52 #pragma pack(pop)
54 // IVF is a simple container format for video frame. It is used by libvpx to
55 // transport VP8 and VP9 bitstream.
56 class MEDIA_EXPORT IvfParser {
57 public:
58 IvfParser();
60 // Initializes the parser for IVF |stream| with size |size| and parses the
61 // file header. Returns true on success.
62 bool Initialize(const uint8_t* stream,
63 size_t size,
64 IvfFileHeader* file_header);
66 // Parses the next frame. Returns true if the next frame is parsed without
67 // error. |frame_header| will be filled with the frame header and |payload|
68 // will point to frame payload (inside the |stream| buffer given to
69 // Initialize.)
70 bool ParseNextFrame(IvfFrameHeader* frame_header, const uint8_t** payload);
72 private:
73 bool ParseFileHeader(IvfFileHeader* file_header);
75 // Current reading position of input stream.
76 const uint8_t* ptr_;
78 // The end position of input stream.
79 const uint8_t* end_;
81 DISALLOW_COPY_AND_ASSIGN(IvfParser);
84 } // namespace media
86 #endif // MEDIA_FILTERS_IVF_PARSER_H_