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

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

Issue 8775035: Add support for incremental cluster parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address CR comments & include new unit tests this time" Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "media/webm/webm_constants.h" 8 #include "media/webm/webm_constants.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 static const base::TimeDelta kNoDuration =
13 base::TimeDelta::FromMicroseconds(-1);
14
12 WebMTracksParser::WebMTracksParser(int64 timecode_scale) 15 WebMTracksParser::WebMTracksParser(int64 timecode_scale)
13 : timecode_scale_(timecode_scale), 16 : timecode_scale_(timecode_scale),
14 track_type_(-1), 17 track_type_(-1),
15 track_num_(-1), 18 track_num_(-1),
16 track_default_duration_(-1), 19 track_default_duration_(-1),
17 audio_track_num_(-1), 20 audio_track_num_(-1),
18 audio_default_duration_(base::TimeDelta::FromMicroseconds(-1)), 21 audio_default_duration_(kNoDuration),
19 video_track_num_(-1), 22 video_track_num_(-1),
20 video_default_duration_(base::TimeDelta::FromMicroseconds(-1)) { 23 video_default_duration_(kNoDuration) {
21 } 24 }
22 25
23 WebMTracksParser::~WebMTracksParser() {} 26 WebMTracksParser::~WebMTracksParser() {}
24 27
25 int WebMTracksParser::Parse(const uint8* buf, int size) { 28 int WebMTracksParser::Parse(const uint8* buf, int size) {
26 return WebMParseListElement(buf, size, kWebMIdTracks, 1, this); 29 track_type_ =-1;
30 track_num_ = -1;
31 track_default_duration_ = -1;
32 audio_track_num_ = -1;
33 audio_default_duration_ = kNoDuration;
34 video_track_num_ = -1;
35 video_default_duration_ = kNoDuration;
36
37 WebMListParser parser(kWebMIdTracks);
38 int result = parser.Parse(buf, size, this);
39
40 if (result <= 0)
41 return result;
42
43 // For now we do all or nothing parsing.
44 return parser.IsParsingComplete() ? result : 0;
27 } 45 }
28 46
29 47
30 bool WebMTracksParser::OnListStart(int id) { 48 bool WebMTracksParser::OnListStart(int id) {
31 if (id == kWebMIdTrackEntry) { 49 if (id == kWebMIdTrackEntry) {
32 track_type_ = -1; 50 track_type_ = -1;
33 track_num_ = -1; 51 track_num_ = -1;
34 track_default_duration_ = -1; 52 track_default_duration_ = -1;
35 } 53 }
36 54
37 return true; 55 return true;
38 } 56 }
39 57
40 bool WebMTracksParser::OnListEnd(int id) { 58 bool WebMTracksParser::OnListEnd(int id) {
41 if (id == kWebMIdTrackEntry) { 59 if (id == kWebMIdTrackEntry) {
42 if (track_type_ == -1 || track_num_ == -1) { 60 if (track_type_ == -1 || track_num_ == -1) {
43 VLOG(1) << "Missing TrackEntry data" 61 DVLOG(1) << "Missing TrackEntry data"
44 << " TrackType " << track_type_ 62 << " TrackType " << track_type_
45 << " TrackNum " << track_num_; 63 << " TrackNum " << track_num_;
46 return false; 64 return false;
47 } 65 }
48 66
49 // Convert nanoseconds to base::TimeDelta. 67 // Convert nanoseconds to base::TimeDelta.
50 base::TimeDelta default_duration = base::TimeDelta::FromMicroseconds( 68 base::TimeDelta default_duration = base::TimeDelta::FromMicroseconds(
51 track_default_duration_ / 1000.0); 69 track_default_duration_ / 1000.0);
52 70
53 if (track_type_ == kWebMTrackTypeVideo) { 71 if (track_type_ == kWebMTrackTypeVideo) {
54 video_track_num_ = track_num_; 72 video_track_num_ = track_num_;
55 video_default_duration_ = default_duration; 73 video_default_duration_ = default_duration;
56 } else if (track_type_ == kWebMTrackTypeAudio) { 74 } else if (track_type_ == kWebMTrackTypeAudio) {
57 audio_track_num_ = track_num_; 75 audio_track_num_ = track_num_;
58 audio_default_duration_ = default_duration; 76 audio_default_duration_ = default_duration;
59 } else { 77 } else {
60 VLOG(1) << "Unexpected TrackType " << track_type_; 78 DVLOG(1) << "Unexpected TrackType " << track_type_;
61 return false; 79 return false;
62 } 80 }
63 81
64 track_type_ = -1; 82 track_type_ = -1;
65 track_num_ = -1; 83 track_num_ = -1;
66 } 84 }
67 85
68 return true; 86 return true;
69 } 87 }
70 88
71 bool WebMTracksParser::OnUInt(int id, int64 val) { 89 bool WebMTracksParser::OnUInt(int id, int64 val) {
72 int64* dst = NULL; 90 int64* dst = NULL;
73 91
74 switch (id) { 92 switch (id) {
75 case kWebMIdTrackNumber: 93 case kWebMIdTrackNumber:
76 dst = &track_num_; 94 dst = &track_num_;
77 break; 95 break;
78 case kWebMIdTrackType: 96 case kWebMIdTrackType:
79 dst = &track_type_; 97 dst = &track_type_;
80 break; 98 break;
81 case kWebMIdDefaultDuration: 99 case kWebMIdDefaultDuration:
82 dst = &track_default_duration_; 100 dst = &track_default_duration_;
83 break; 101 break;
84 default: 102 default:
85 return true; 103 return true;
86 } 104 }
87 105
88 if (*dst != -1) { 106 if (*dst != -1) {
89 VLOG(1) << "Multiple values for id " << std::hex << id << " specified"; 107 DVLOG(1) << "Multiple values for id " << std::hex << id << " specified";
90 return false; 108 return false;
91 } 109 }
92 110
93 *dst = val; 111 *dst = val;
94 return true; 112 return true;
95 } 113 }
96 114
97 bool WebMTracksParser::OnFloat(int id, double val) { 115 bool WebMTracksParser::OnFloat(int id, double val) {
98 VLOG(1) << "Unexpected float for id" << std::hex << id; 116 DVLOG(1) << "Unexpected float for id" << std::hex << id;
99 return false; 117 return false;
100 } 118 }
101 119
102 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { 120 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) {
103 return true; 121 return true;
104 } 122 }
105 123
106 bool WebMTracksParser::OnString(int id, const std::string& str) { 124 bool WebMTracksParser::OnString(int id, const std::string& str) {
107 if (id != kWebMIdCodecID) 125 if (id != kWebMIdCodecID)
108 return false; 126 return false;
109 127
110 if (str != "A_VORBIS" && str != "V_VP8") { 128 if (str != "A_VORBIS" && str != "V_VP8") {
111 VLOG(1) << "Unexpected CodecID " << str; 129 DVLOG(1) << "Unexpected CodecID " << str;
112 return false; 130 return false;
113 } 131 }
114 132
115 return true; 133 return true;
116 } 134 }
117 135
118 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags, 136 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags,
119 const uint8* data, int size) { 137 const uint8* data, int size) {
120 return false; 138 return false;
121 } 139 }
122 140
123 } // namespace media 141 } // namespace media
OLDNEW
« media/webm/webm_parser_unittest.cc ('K') | « media/webm/webm_parser_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698