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

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

Issue 10382200: Update WebMClusterParser to compute durations for all StreamParserBuffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address CR comments Created 8 years, 7 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_cluster_parser_unittest.cc ('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/webm/webm_constants.h" 10 #include "media/webm/webm_constants.h"
10 #include "media/webm/webm_content_encodings.h" 11 #include "media/webm/webm_content_encodings.h"
11 12
12 namespace media { 13 namespace media {
13 14
14 // Values for TrackType element. 15 // Values for TrackType element.
15 static const int kWebMTrackTypeVideo = 1; 16 static const int kWebMTrackTypeVideo = 1;
16 static const int kWebMTrackTypeAudio = 2; 17 static const int kWebMTrackTypeAudio = 2;
17 18
18 WebMTracksParser::WebMTracksParser(int64 timecode_scale) 19 WebMTracksParser::WebMTracksParser(int64 timecode_scale)
19 : timecode_scale_(timecode_scale), 20 : timecode_scale_(timecode_scale),
20 track_type_(-1), 21 track_type_(-1),
21 track_num_(-1), 22 track_num_(-1),
22 track_default_duration_(-1), 23 track_default_duration_(-1),
23 audio_track_num_(-1), 24 audio_track_num_(-1),
24 video_track_num_(-1) { 25 audio_default_duration_(kNoTimestamp()),
26 video_track_num_(-1),
27 video_default_duration_(kNoTimestamp()) {
25 } 28 }
26 29
27 WebMTracksParser::~WebMTracksParser() {} 30 WebMTracksParser::~WebMTracksParser() {}
28 31
29 const uint8* WebMTracksParser::video_encryption_key_id() const { 32 const uint8* WebMTracksParser::video_encryption_key_id() const {
30 if (!video_content_encodings_client_.get()) 33 if (!video_content_encodings_client_.get())
31 return NULL; 34 return NULL;
32 35
33 DCHECK(!video_content_encodings_client_->content_encodings().empty()); 36 DCHECK(!video_content_encodings_client_->content_encodings().empty());
34 return video_content_encodings_client_->content_encodings()[0]-> 37 return video_content_encodings_client_->content_encodings()[0]->
35 encryption_key_id(); 38 encryption_key_id();
36 } 39 }
37 40
38 int WebMTracksParser::video_encryption_key_id_size() const { 41 int WebMTracksParser::video_encryption_key_id_size() const {
39 if (!video_content_encodings_client_.get()) 42 if (!video_content_encodings_client_.get())
40 return 0; 43 return 0;
41 44
42 DCHECK(!video_content_encodings_client_->content_encodings().empty()); 45 DCHECK(!video_content_encodings_client_->content_encodings().empty());
43 return video_content_encodings_client_->content_encodings()[0]-> 46 return video_content_encodings_client_->content_encodings()[0]->
44 encryption_key_id_size(); 47 encryption_key_id_size();
45 } 48 }
46 49
47 int WebMTracksParser::Parse(const uint8* buf, int size) { 50 int WebMTracksParser::Parse(const uint8* buf, int size) {
48 track_type_ =-1; 51 track_type_ =-1;
49 track_num_ = -1; 52 track_num_ = -1;
50 track_default_duration_ = -1; 53 track_default_duration_ = -1;
51 audio_track_num_ = -1; 54 audio_track_num_ = -1;
52 audio_default_duration_ = base::TimeDelta(); 55 audio_default_duration_ = kNoTimestamp();
53 video_track_num_ = -1; 56 video_track_num_ = -1;
54 video_default_duration_ = base::TimeDelta(); 57 video_default_duration_ = kNoTimestamp();
55 58
56 WebMListParser parser(kWebMIdTracks, this); 59 WebMListParser parser(kWebMIdTracks, this);
57 int result = parser.Parse(buf, size); 60 int result = parser.Parse(buf, size);
58 61
59 if (result <= 0) 62 if (result <= 0)
60 return result; 63 return result;
61 64
62 // For now we do all or nothing parsing. 65 // For now we do all or nothing parsing.
63 return parser.IsParsingComplete() ? result : 0; 66 return parser.IsParsingComplete() ? result : 0;
64 } 67 }
(...skipping 23 matching lines...) Expand all
88 } 91 }
89 92
90 if (id == kWebMIdTrackEntry) { 93 if (id == kWebMIdTrackEntry) {
91 if (track_type_ == -1 || track_num_ == -1) { 94 if (track_type_ == -1 || track_num_ == -1) {
92 DVLOG(1) << "Missing TrackEntry data" 95 DVLOG(1) << "Missing TrackEntry data"
93 << " TrackType " << track_type_ 96 << " TrackType " << track_type_
94 << " TrackNum " << track_num_; 97 << " TrackNum " << track_num_;
95 return false; 98 return false;
96 } 99 }
97 100
98 base::TimeDelta default_duration; 101 base::TimeDelta default_duration = kNoTimestamp();
99 102
100 if (track_default_duration_ > 0) { 103 if (track_default_duration_ > 0) {
101 // Convert nanoseconds to base::TimeDelta. 104 // Convert nanoseconds to base::TimeDelta.
102 default_duration = base::TimeDelta::FromMicroseconds( 105 default_duration = base::TimeDelta::FromMicroseconds(
103 track_default_duration_ / 1000.0); 106 track_default_duration_ / 1000.0);
104 } 107 }
105 108
106 if (track_type_ == kWebMTrackTypeVideo) { 109 if (track_type_ == kWebMTrackTypeVideo) {
107 video_track_num_ = track_num_; 110 video_track_num_ = track_num_;
108 video_default_duration_ = default_duration; 111 video_default_duration_ = default_duration;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 bool WebMTracksParser::OnString(int id, const std::string& str) { 171 bool WebMTracksParser::OnString(int id, const std::string& str) {
169 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { 172 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") {
170 DVLOG(1) << "Unexpected CodecID " << str; 173 DVLOG(1) << "Unexpected CodecID " << str;
171 return false; 174 return false;
172 } 175 }
173 176
174 return true; 177 return true;
175 } 178 }
176 179
177 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/webm_cluster_parser_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698