Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: media/filters/h264_bit_reader.h

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This file contains an implementation of an H264 Annex-B video stream parser. 5 // This file contains an implementation of an H264 Annex-B video stream parser.
6 6
7 #ifndef MEDIA_FILTERS_H264_BIT_READER_H_ 7 #ifndef MEDIA_FILTERS_H264_BIT_READER_H_
8 #define MEDIA_FILTERS_H264_BIT_READER_H_ 8 #define MEDIA_FILTERS_H264_BIT_READER_H_
9 9
10 #include <stdint.h>
10 #include <sys/types.h> 11 #include <sys/types.h>
11 12
12 #include "base/basictypes.h" 13 #include "base/macros.h"
13 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
14 15
15 namespace media { 16 namespace media {
16 17
17 // A class to provide bit-granularity reading of H.264 streams. 18 // A class to provide bit-granularity reading of H.264 streams.
18 // This is not a generic bit reader class, as it takes into account 19 // This is not a generic bit reader class, as it takes into account
19 // H.264 stream-specific constraints, such as skipping emulation-prevention 20 // H.264 stream-specific constraints, such as skipping emulation-prevention
20 // bytes and stop bits. See spec for more details. 21 // bytes and stop bits. See spec for more details.
21 class MEDIA_EXPORT H264BitReader { 22 class MEDIA_EXPORT H264BitReader {
22 public: 23 public:
23 H264BitReader(); 24 H264BitReader();
24 ~H264BitReader(); 25 ~H264BitReader();
25 26
26 // Initialize the reader to start reading at |data|, |size| being size 27 // Initialize the reader to start reading at |data|, |size| being size
27 // of |data| in bytes. 28 // of |data| in bytes.
28 // Return false on insufficient size of stream.. 29 // Return false on insufficient size of stream..
29 // TODO(posciak,fischman): consider replacing Initialize() with 30 // TODO(posciak,fischman): consider replacing Initialize() with
30 // heap-allocating and creating bit readers on demand instead. 31 // heap-allocating and creating bit readers on demand instead.
31 bool Initialize(const uint8* data, off_t size); 32 bool Initialize(const uint8_t* data, off_t size);
32 33
33 // Read |num_bits| next bits from stream and return in |*out|, first bit 34 // Read |num_bits| next bits from stream and return in |*out|, first bit
34 // from the stream starting at |num_bits| position in |*out|. 35 // from the stream starting at |num_bits| position in |*out|.
35 // |num_bits| may be 1-32, inclusive. 36 // |num_bits| may be 1-32, inclusive.
36 // Return false if the given number of bits cannot be read (not enough 37 // Return false if the given number of bits cannot be read (not enough
37 // bits in the stream), true otherwise. 38 // bits in the stream), true otherwise.
38 bool ReadBits(int num_bits, int* out); 39 bool ReadBits(int num_bits, int* out);
39 40
40 // Return the number of bits left in the stream. 41 // Return the number of bits left in the stream.
41 off_t NumBitsLeft(); 42 off_t NumBitsLeft();
42 43
43 // See the definition of more_rbsp_data() in spec. 44 // See the definition of more_rbsp_data() in spec.
44 bool HasMoreRBSPData(); 45 bool HasMoreRBSPData();
45 46
46 // Return the number of emulation prevention bytes already read. 47 // Return the number of emulation prevention bytes already read.
47 size_t NumEmulationPreventionBytesRead(); 48 size_t NumEmulationPreventionBytesRead();
48 49
49 private: 50 private:
50 // Advance to the next byte, loading it into curr_byte_. 51 // Advance to the next byte, loading it into curr_byte_.
51 // Return false on end of stream. 52 // Return false on end of stream.
52 bool UpdateCurrByte(); 53 bool UpdateCurrByte();
53 54
54 // Pointer to the next unread (not in curr_byte_) byte in the stream. 55 // Pointer to the next unread (not in curr_byte_) byte in the stream.
55 const uint8* data_; 56 const uint8_t* data_;
56 57
57 // Bytes left in the stream (without the curr_byte_). 58 // Bytes left in the stream (without the curr_byte_).
58 off_t bytes_left_; 59 off_t bytes_left_;
59 60
60 // Contents of the current byte; first unread bit starting at position 61 // Contents of the current byte; first unread bit starting at position
61 // 8 - num_remaining_bits_in_curr_byte_ from MSB. 62 // 8 - num_remaining_bits_in_curr_byte_ from MSB.
62 int curr_byte_; 63 int curr_byte_;
63 64
64 // Number of bits remaining in curr_byte_ 65 // Number of bits remaining in curr_byte_
65 int num_remaining_bits_in_curr_byte_; 66 int num_remaining_bits_in_curr_byte_;
66 67
67 // Used in emulation prevention three byte detection (see spec). 68 // Used in emulation prevention three byte detection (see spec).
68 // Initially set to 0xffff to accept all initial two-byte sequences. 69 // Initially set to 0xffff to accept all initial two-byte sequences.
69 int prev_two_bytes_; 70 int prev_two_bytes_;
70 71
71 // Number of emulation preventation bytes (0x000003) we met. 72 // Number of emulation preventation bytes (0x000003) we met.
72 size_t emulation_prevention_bytes_; 73 size_t emulation_prevention_bytes_;
73 74
74 DISALLOW_COPY_AND_ASSIGN(H264BitReader); 75 DISALLOW_COPY_AND_ASSIGN(H264BitReader);
75 }; 76 };
76 77
77 } // namespace media 78 } // namespace media
78 79
79 #endif // MEDIA_FILTERS_H264_BIT_READER_H_ 80 #endif // MEDIA_FILTERS_H264_BIT_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698