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

Side by Side Diff: media/webm/webm_tracks_parser.cc

Issue 11088047: Support encrypted audio stream in demuxer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « media/webm/webm_tracks_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/webm/webm_tracks_parser.h" 5 #include "media/webm/webm_tracks_parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "media/base/buffers.h" 9 #include "media/base/buffers.h"
10 #include "media/webm/webm_constants.h" 10 #include "media/webm/webm_constants.h"
11 #include "media/webm/webm_content_encodings.h" 11 #include "media/webm/webm_content_encodings.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 // Values for TrackType element. 15 // Values for TrackType element.
16 static const int kWebMTrackTypeVideo = 1; 16 static const int kWebMTrackTypeVideo = 1;
17 static const int kWebMTrackTypeAudio = 2; 17 static const int kWebMTrackTypeAudio = 2;
18 18
19 WebMTracksParser::WebMTracksParser() 19 WebMTracksParser::WebMTracksParser()
20 : track_type_(-1), 20 : track_type_(-1),
21 track_num_(-1), 21 track_num_(-1),
22 audio_track_num_(-1), 22 audio_track_num_(-1),
23 video_track_num_(-1) { 23 video_track_num_(-1) {
24 } 24 }
25 25
26 WebMTracksParser::~WebMTracksParser() {} 26 WebMTracksParser::~WebMTracksParser() {}
27 27
28 const std::string& WebMTracksParser::video_encryption_key_id() const {
29 if (!video_content_encodings_client_.get())
30 return EmptyString();
31
32 DCHECK(!video_content_encodings_client_->content_encodings().empty());
33 return video_content_encodings_client_->content_encodings()[0]->
34 encryption_key_id();
35 }
36
37 int WebMTracksParser::Parse(const uint8* buf, int size) { 28 int WebMTracksParser::Parse(const uint8* buf, int size) {
38 track_type_ =-1; 29 track_type_ =-1;
39 track_num_ = -1; 30 track_num_ = -1;
40 audio_track_num_ = -1; 31 audio_track_num_ = -1;
41 video_track_num_ = -1; 32 video_track_num_ = -1;
42 33
43 WebMListParser parser(kWebMIdTracks, this); 34 WebMListParser parser(kWebMIdTracks, this);
44 int result = parser.Parse(buf, size); 35 int result = parser.Parse(buf, size);
45 36
46 if (result <= 0) 37 if (result <= 0)
47 return result; 38 return result;
48 39
49 // For now we do all or nothing parsing. 40 // For now we do all or nothing parsing.
50 return parser.IsParsingComplete() ? result : 0; 41 return parser.IsParsingComplete() ? result : 0;
51 } 42 }
52 43
53
54 WebMParserClient* WebMTracksParser::OnListStart(int id) { 44 WebMParserClient* WebMTracksParser::OnListStart(int id) {
55 if (id == kWebMIdContentEncodings) { 45 if (id == kWebMIdContentEncodings) {
56 DCHECK(!track_content_encodings_client_.get()); 46 DCHECK(!track_content_encodings_client_.get());
57 track_content_encodings_client_.reset(new WebMContentEncodingsClient); 47 track_content_encodings_client_.reset(new WebMContentEncodingsClient);
58 return track_content_encodings_client_->OnListStart(id); 48 return track_content_encodings_client_->OnListStart(id);
59 } 49 }
60 50
61 if (id == kWebMIdTrackEntry) { 51 if (id == kWebMIdTrackEntry) {
62 track_type_ = -1; 52 track_type_ = -1;
63 track_num_ = -1; 53 track_num_ = -1;
(...skipping 10 matching lines...) Expand all
74 } 64 }
75 65
76 if (id == kWebMIdTrackEntry) { 66 if (id == kWebMIdTrackEntry) {
77 if (track_type_ == -1 || track_num_ == -1) { 67 if (track_type_ == -1 || track_num_ == -1) {
78 DVLOG(1) << "Missing TrackEntry data" 68 DVLOG(1) << "Missing TrackEntry data"
79 << " TrackType " << track_type_ 69 << " TrackType " << track_type_
80 << " TrackNum " << track_num_; 70 << " TrackNum " << track_num_;
81 return false; 71 return false;
82 } 72 }
83 73
84 if (track_type_ == kWebMTrackTypeVideo) { 74 if (track_type_ != kWebMTrackTypeAudio &&
85 video_track_num_ = track_num_; 75 track_type_ != kWebMTrackTypeVideo) {
86 if (track_content_encodings_client_.get()) {
87 video_content_encodings_client_ =
88 track_content_encodings_client_.Pass();
89 }
90 } else if (track_type_ == kWebMTrackTypeAudio) {
91 audio_track_num_ = track_num_;
92 if (track_content_encodings_client_.get()) {
93 audio_content_encodings_client_ =
94 track_content_encodings_client_.Pass();
95 }
96 } else {
97 DVLOG(1) << "Unexpected TrackType " << track_type_; 76 DVLOG(1) << "Unexpected TrackType " << track_type_;
98 return false; 77 return false;
99 } 78 }
100 79
80 std::string encryption_key_id;
81 if (track_content_encodings_client_.get()) {
82 DCHECK(!track_content_encodings_client_->content_encodings().empty());
83 // If we have multiple ContentEncoding in one track. Always choose the
84 // key id in the first ContentEncoding as the key id of the track.
85 encryption_key_id = track_content_encodings_client_->
86 content_encodings()[0]->encryption_key_id();
87 }
88
89 if (track_type_ == kWebMTrackTypeAudio) {
90 audio_track_num_ = track_num_;
91 audio_encryption_key_id_ = encryption_key_id;
92 } else if (track_type_ == kWebMTrackTypeVideo) {
93 video_track_num_ = track_num_;
94 video_encryption_key_id_ = encryption_key_id;
95 }
96
101 track_type_ = -1; 97 track_type_ = -1;
102 track_num_ = -1; 98 track_num_ = -1;
103 track_content_encodings_client_.reset(); 99 track_content_encodings_client_.reset();
104 return true; 100 return true;
105 } 101 }
106 102
107 return true; 103 return true;
108 } 104 }
109 105
110 bool WebMTracksParser::OnUInt(int id, int64 val) { 106 bool WebMTracksParser::OnUInt(int id, int64 val) {
(...skipping 30 matching lines...) Expand all
141 bool WebMTracksParser::OnString(int id, const std::string& str) { 137 bool WebMTracksParser::OnString(int id, const std::string& str) {
142 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { 138 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") {
143 DVLOG(1) << "Unexpected CodecID " << str; 139 DVLOG(1) << "Unexpected CodecID " << str;
144 return false; 140 return false;
145 } 141 }
146 142
147 return true; 143 return true;
148 } 144 }
149 145
150 } // namespace media 146 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/webm_tracks_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698