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

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

Issue 379983002: Fix AnnexB validation logic to work with encrypted content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 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_PARSER_H_ 7 #ifndef MEDIA_FILTERS_H264_PARSER_H_
8 #define MEDIA_FILTERS_H264_PARSER_H_ 8 #define MEDIA_FILTERS_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 "media/base/media_export.h" 15 #include "media/base/media_export.h"
16 #include "media/base/ranges.h"
16 #include "media/filters/h264_bit_reader.h" 17 #include "media/filters/h264_bit_reader.h"
17 18
18 namespace media { 19 namespace media {
19 20
21 struct SubsampleEntry;
22
20 // For explanations of each struct and its members, see H.264 specification 23 // For explanations of each struct and its members, see H.264 specification
21 // at http://www.itu.int/rec/T-REC-H.264. 24 // at http://www.itu.int/rec/T-REC-H.264.
22 struct MEDIA_EXPORT H264NALU { 25 struct MEDIA_EXPORT H264NALU {
23 H264NALU(); 26 H264NALU();
24 27
25 enum Type { 28 enum Type {
26 kUnspecified = 0, 29 kUnspecified = 0,
27 kNonIDRSlice = 1, 30 kNonIDRSlice = 1,
28 kSliceDataA = 2, 31 kSliceDataA = 2,
29 kSliceDataB = 3, 32 kSliceDataB = 3,
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // - |*start_code_size| is either 0, 3 or 4. 333 // - |*start_code_size| is either 0, 3 or 4.
331 static bool FindStartCode(const uint8* data, off_t data_size, 334 static bool FindStartCode(const uint8* data, off_t data_size,
332 off_t* offset, off_t* start_code_size); 335 off_t* offset, off_t* start_code_size);
333 336
334 H264Parser(); 337 H264Parser();
335 ~H264Parser(); 338 ~H264Parser();
336 339
337 void Reset(); 340 void Reset();
338 // Set current stream pointer to |stream| of |stream_size| in bytes, 341 // Set current stream pointer to |stream| of |stream_size| in bytes,
339 // |stream| owned by caller. 342 // |stream| owned by caller.
343 // |subsamples| contains information about what parts of |stream| are
344 // encrypted.
340 void SetStream(const uint8* stream, off_t stream_size); 345 void SetStream(const uint8* stream, off_t stream_size);
346 void SetStream(const uint8* stream, off_t stream_size,
347 const std::vector<SubsampleEntry>& subsamples);
xhwang 2014/07/10 06:23:01 nit: The style guide doesn't encourage function ov
xhwang 2014/07/10 06:23:01 nit: Add include for vector.
acolwell GONE FROM CHROMIUM 2014/07/15 22:10:44 Done.
acolwell GONE FROM CHROMIUM 2014/07/15 22:10:44 Done.
341 348
342 // Read the stream to find the next NALU, identify it and return 349 // Read the stream to find the next NALU, identify it and return
343 // that information in |*nalu|. This advances the stream to the beginning 350 // that information in |*nalu|. This advances the stream to the beginning
344 // of this NALU, but not past it, so subsequent calls to NALU-specific 351 // of this NALU, but not past it, so subsequent calls to NALU-specific
345 // parsing functions (ParseSPS, etc.) will parse this NALU. 352 // parsing functions (ParseSPS, etc.) will parse this NALU.
346 // If the caller wishes to skip the current NALU, it can call this function 353 // If the caller wishes to skip the current NALU, it can call this function
347 // again, instead of any NALU-type specific parse functions below. 354 // again, instead of any NALU-type specific parse functions below.
348 Result AdvanceToNextNALU(H264NALU* nalu); 355 Result AdvanceToNextNALU(H264NALU* nalu);
349 356
350 // NALU-specific parsing functions. 357 // NALU-specific parsing functions.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 private: 392 private:
386 // Move the stream pointer to the beginning of the next NALU, 393 // Move the stream pointer to the beginning of the next NALU,
387 // i.e. pointing at the next start code. 394 // i.e. pointing at the next start code.
388 // Return true if a NALU has been found. 395 // Return true if a NALU has been found.
389 // If a NALU is found: 396 // If a NALU is found:
390 // - its size in bytes is returned in |*nalu_size| and includes 397 // - its size in bytes is returned in |*nalu_size| and includes
391 // the start code as well as the trailing zero bits. 398 // the start code as well as the trailing zero bits.
392 // - the size in bytes of the start code is returned in |*start_code_size|. 399 // - the size in bytes of the start code is returned in |*start_code_size|.
393 bool LocateNALU(off_t* nalu_size, off_t* start_code_size); 400 bool LocateNALU(off_t* nalu_size, off_t* start_code_size);
394 401
402 // Wrapper for FindStartCode() that skips over start codes that
403 // may appear inside |encrypted_ranges_|.
404 bool FindNextStartCode(const uint8* data, off_t data_size,
xhwang 2014/07/10 06:23:01 It's not obvious to know the difference b/w FindSt
acolwell GONE FROM CHROMIUM 2014/07/15 22:10:44 Done.
405 off_t* offset, off_t* start_code_size);
406
395 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec. 407 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec.
396 // Read one unsigned exp-Golomb code from the stream and return in |*val|. 408 // Read one unsigned exp-Golomb code from the stream and return in |*val|.
397 Result ReadUE(int* val); 409 Result ReadUE(int* val);
398 410
399 // Read one signed exp-Golomb code from the stream and return in |*val|. 411 // Read one signed exp-Golomb code from the stream and return in |*val|.
400 Result ReadSE(int* val); 412 Result ReadSE(int* val);
401 413
402 // Parse scaling lists (see spec). 414 // Parse scaling lists (see spec).
403 Result ParseScalingList(int size, int* scaling_list, bool* use_default); 415 Result ParseScalingList(int size, int* scaling_list, bool* use_default);
404 Result ParseSPSScalingLists(H264SPS* sps); 416 Result ParseSPSScalingLists(H264SPS* sps);
(...skipping 29 matching lines...) Expand all
434 off_t bytes_left_; 446 off_t bytes_left_;
435 447
436 H264BitReader br_; 448 H264BitReader br_;
437 449
438 // PPSes and SPSes stored for future reference. 450 // PPSes and SPSes stored for future reference.
439 typedef std::map<int, H264SPS*> SPSById; 451 typedef std::map<int, H264SPS*> SPSById;
440 typedef std::map<int, H264PPS*> PPSById; 452 typedef std::map<int, H264PPS*> PPSById;
441 SPSById active_SPSes_; 453 SPSById active_SPSes_;
442 PPSById active_PPSes_; 454 PPSById active_PPSes_;
443 455
456 Ranges<const uint8*> encrypted_ranges_;
xhwang 2014/07/10 06:23:01 Since this range is only used for searching for st
acolwell GONE FROM CHROMIUM 2014/07/15 22:10:44 Done.
457
444 DISALLOW_COPY_AND_ASSIGN(H264Parser); 458 DISALLOW_COPY_AND_ASSIGN(H264Parser);
445 }; 459 };
446 460
447 } // namespace media 461 } // namespace media
448 462
449 #endif // MEDIA_FILTERS_H264_PARSER_H_ 463 #endif // MEDIA_FILTERS_H264_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698