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

Side by Side Diff: content/common/gpu/media/h264_parser.h

Issue 10710002: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Explicitly check if audio is AAC. Created 8 years, 5 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 7 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
9 9
10 #include <sys/types.h> 10 #include <sys/types.h>
11 11
12 #include <map> 12 #include <map>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
acolwell GONE FROM CHROMIUM 2012/07/03 01:00:12 Why is this needed now?
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/common/gpu/media/h264_bit_reader.h"
16 18
17 namespace content { 19 namespace content {
18 20
19 // For explanations of each struct and its members, see H.264 specification 21 // For explanations of each struct and its members, see H.264 specification
20 // at http://www.itu.int/rec/T-REC-H.264. 22 // at http://www.itu.int/rec/T-REC-H.264.
21 struct CONTENT_EXPORT H264NALU { 23 struct CONTENT_EXPORT H264NALU {
22 H264NALU(); 24 H264NALU();
23 25
24 enum Type { 26 enum Type {
25 kUnspecified = 0, 27 kUnspecified = 0,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 296
295 // Parse a slice header, returning it in |*shdr|. |*nalu| must be set to 297 // Parse a slice header, returning it in |*shdr|. |*nalu| must be set to
296 // the NALU returned from AdvanceToNextNALU() and corresponding to |*shdr|. 298 // the NALU returned from AdvanceToNextNALU() and corresponding to |*shdr|.
297 Result ParseSliceHeader(const H264NALU& nalu, H264SliceHeader* shdr); 299 Result ParseSliceHeader(const H264NALU& nalu, H264SliceHeader* shdr);
298 300
299 // Parse a SEI message, returning it in |*sei_msg|, provided and managed 301 // Parse a SEI message, returning it in |*sei_msg|, provided and managed
300 // by the caller. 302 // by the caller.
301 Result ParseSEI(H264SEIMessage* sei_msg); 303 Result ParseSEI(H264SEIMessage* sei_msg);
302 304
303 private: 305 private:
304 // A class to provide bit-granularity reading of H.264 streams.
305 // This is not a generic bit reader class, as it takes into account
306 // H.264 stream-specific constraints, such as skipping emulation-prevention
307 // bytes and stop bits. See spec for more details.
308 // TODO(posciak): need separate unittests for this class.
309 class H264BitReader {
310 public:
311 H264BitReader();
312 ~H264BitReader();
313
314 // Initialize the reader to start reading at |data|, |size| being size
315 // of |data| in bytes.
316 // Return false on insufficient size of stream..
317 // TODO(posciak,fischman): consider replacing Initialize() with
318 // heap-allocating and creating bit readers on demand instead.
319 bool Initialize(const uint8* data, off_t size);
320
321 // Read |num_bits| next bits from stream and return in |*out|, first bit
322 // from the stream starting at |num_bits| position in |*out|.
323 // |num_bits| may be 1-32, inclusive.
324 // Return false if the given number of bits cannot be read (not enough
325 // bits in the stream), true otherwise.
326 bool ReadBits(int num_bits, int *out);
327
328 // Return the number of bits left in the stream.
329 off_t NumBitsLeft();
330
331 // See the definition of more_rbsp_data() in spec.
332 bool HasMoreRBSPData();
333
334 private:
335 // Advance to the next byte, loading it into curr_byte_.
336 // Return false on end of stream.
337 bool UpdateCurrByte();
338
339 // Pointer to the next unread (not in curr_byte_) byte in the stream.
340 const uint8* data_;
341
342 // Bytes left in the stream (without the curr_byte_).
343 off_t bytes_left_;
344
345 // Contents of the current byte; first unread bit starting at position
346 // 8 - num_remaining_bits_in_curr_byte_ from MSB.
347 int curr_byte_;
348
349 // Number of bits remaining in curr_byte_
350 int num_remaining_bits_in_curr_byte_;
351
352 // Used in emulation prevention three byte detection (see spec).
353 // Initially set to 0xffff to accept all initial two-byte sequences.
354 int prev_two_bytes_;
355
356 DISALLOW_COPY_AND_ASSIGN(H264BitReader);
357 };
358
359 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec. 306 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec.
360 // Read one unsigned exp-Golomb code from the stream and return in |*val|. 307 // Read one unsigned exp-Golomb code from the stream and return in |*val|.
361 Result ReadUE(int* val); 308 Result ReadUE(int* val);
362 309
363 // Read one signed exp-Golomb code from the stream and return in |*val|. 310 // Read one signed exp-Golomb code from the stream and return in |*val|.
364 Result ReadSE(int* val); 311 Result ReadSE(int* val);
365 312
366 // Parse scaling lists (see spec). 313 // Parse scaling lists (see spec).
367 Result ParseScalingList(int size, int* scaling_list, bool* use_default); 314 Result ParseScalingList(int size, int* scaling_list, bool* use_default);
368 Result ParseSPSScalingLists(H264SPS* sps); 315 Result ParseSPSScalingLists(H264SPS* sps);
(...skipping 30 matching lines...) Expand all
399 typedef std::map<int, H264PPS*> PPSById; 346 typedef std::map<int, H264PPS*> PPSById;
400 SPSById active_SPSes_; 347 SPSById active_SPSes_;
401 PPSById active_PPSes_; 348 PPSById active_PPSes_;
402 349
403 DISALLOW_COPY_AND_ASSIGN(H264Parser); 350 DISALLOW_COPY_AND_ASSIGN(H264Parser);
404 }; 351 };
405 352
406 } // namespace content 353 } // namespace content
407 354
408 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 355 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698