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

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

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

Powered by Google App Engine
This is Rietveld 408576698