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

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: Address CR comment Created 6 years, 4 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
« no previous file with comments | « media/filters/ffmpeg_demuxer_unittest.cc ('k') | media/filters/h264_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <vector>
13 14
14 #include "base/basictypes.h" 15 #include "base/basictypes.h"
15 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
17 #include "media/base/ranges.h"
16 #include "media/filters/h264_bit_reader.h" 18 #include "media/filters/h264_bit_reader.h"
17 19
18 namespace media { 20 namespace media {
19 21
22 struct SubsampleEntry;
23
20 // For explanations of each struct and its members, see H.264 specification 24 // For explanations of each struct and its members, see H.264 specification
21 // at http://www.itu.int/rec/T-REC-H.264. 25 // at http://www.itu.int/rec/T-REC-H.264.
22 struct MEDIA_EXPORT H264NALU { 26 struct MEDIA_EXPORT H264NALU {
23 H264NALU(); 27 H264NALU();
24 28
25 enum Type { 29 enum Type {
26 kUnspecified = 0, 30 kUnspecified = 0,
27 kNonIDRSlice = 1, 31 kNonIDRSlice = 1,
28 kSliceDataA = 2, 32 kSliceDataA = 2,
29 kSliceDataB = 3, 33 kSliceDataB = 3,
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // - |*start_code_size| is either 0, 3 or 4. 334 // - |*start_code_size| is either 0, 3 or 4.
331 static bool FindStartCode(const uint8* data, off_t data_size, 335 static bool FindStartCode(const uint8* data, off_t data_size,
332 off_t* offset, off_t* start_code_size); 336 off_t* offset, off_t* start_code_size);
333 337
334 H264Parser(); 338 H264Parser();
335 ~H264Parser(); 339 ~H264Parser();
336 340
337 void Reset(); 341 void Reset();
338 // Set current stream pointer to |stream| of |stream_size| in bytes, 342 // Set current stream pointer to |stream| of |stream_size| in bytes,
339 // |stream| owned by caller. 343 // |stream| owned by caller.
344 // |subsamples| contains information about what parts of |stream| are
345 // encrypted.
340 void SetStream(const uint8* stream, off_t stream_size); 346 void SetStream(const uint8* stream, off_t stream_size);
347 void SetEncryptedStream(const uint8* stream, off_t stream_size,
348 const std::vector<SubsampleEntry>& subsamples);
341 349
342 // Read the stream to find the next NALU, identify it and return 350 // Read the stream to find the next NALU, identify it and return
343 // that information in |*nalu|. This advances the stream to the beginning 351 // 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 352 // of this NALU, but not past it, so subsequent calls to NALU-specific
345 // parsing functions (ParseSPS, etc.) will parse this NALU. 353 // parsing functions (ParseSPS, etc.) will parse this NALU.
346 // If the caller wishes to skip the current NALU, it can call this function 354 // 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. 355 // again, instead of any NALU-type specific parse functions below.
348 Result AdvanceToNextNALU(H264NALU* nalu); 356 Result AdvanceToNextNALU(H264NALU* nalu);
349 357
350 // NALU-specific parsing functions. 358 // NALU-specific parsing functions.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 private: 393 private:
386 // Move the stream pointer to the beginning of the next NALU, 394 // Move the stream pointer to the beginning of the next NALU,
387 // i.e. pointing at the next start code. 395 // i.e. pointing at the next start code.
388 // Return true if a NALU has been found. 396 // Return true if a NALU has been found.
389 // If a NALU is found: 397 // If a NALU is found:
390 // - its size in bytes is returned in |*nalu_size| and includes 398 // - its size in bytes is returned in |*nalu_size| and includes
391 // the start code as well as the trailing zero bits. 399 // 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|. 400 // - 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); 401 bool LocateNALU(off_t* nalu_size, off_t* start_code_size);
394 402
403 // Wrapper for FindStartCode() that skips over start codes that
404 // may appear inside of |encrypted_ranges_|.
405 // Returns true if a start code was found. Otherwise returns false.
406 bool FindStartCodeInClearRanges(const uint8* data, off_t data_size,
407 off_t* offset, off_t* start_code_size);
408
395 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec. 409 // 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|. 410 // Read one unsigned exp-Golomb code from the stream and return in |*val|.
397 Result ReadUE(int* val); 411 Result ReadUE(int* val);
398 412
399 // Read one signed exp-Golomb code from the stream and return in |*val|. 413 // Read one signed exp-Golomb code from the stream and return in |*val|.
400 Result ReadSE(int* val); 414 Result ReadSE(int* val);
401 415
402 // Parse scaling lists (see spec). 416 // Parse scaling lists (see spec).
403 Result ParseScalingList(int size, int* scaling_list, bool* use_default); 417 Result ParseScalingList(int size, int* scaling_list, bool* use_default);
404 Result ParseSPSScalingLists(H264SPS* sps); 418 Result ParseSPSScalingLists(H264SPS* sps);
(...skipping 29 matching lines...) Expand all
434 off_t bytes_left_; 448 off_t bytes_left_;
435 449
436 H264BitReader br_; 450 H264BitReader br_;
437 451
438 // PPSes and SPSes stored for future reference. 452 // PPSes and SPSes stored for future reference.
439 typedef std::map<int, H264SPS*> SPSById; 453 typedef std::map<int, H264SPS*> SPSById;
440 typedef std::map<int, H264PPS*> PPSById; 454 typedef std::map<int, H264PPS*> PPSById;
441 SPSById active_SPSes_; 455 SPSById active_SPSes_;
442 PPSById active_PPSes_; 456 PPSById active_PPSes_;
443 457
458 // Ranges of encrypted bytes in the buffer passed to
459 // SetEncryptedStream().
460 Ranges<const uint8*> encrypted_ranges_;
461
444 DISALLOW_COPY_AND_ASSIGN(H264Parser); 462 DISALLOW_COPY_AND_ASSIGN(H264Parser);
445 }; 463 };
446 464
447 } // namespace media 465 } // namespace media
448 466
449 #endif // MEDIA_FILTERS_H264_PARSER_H_ 467 #endif // MEDIA_FILTERS_H264_PARSER_H_
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer_unittest.cc ('k') | media/filters/h264_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698