Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/webm/webm_tracks_parser.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "media/webm/webm_constants.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
|
scherkus (not reviewing)
2011/06/24 18:27:37
remove blank line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
| |
| 12 | |
| 13 WebMTracksParser::WebMTracksParser(int64 timecode_scale) | |
| 14 : timecode_scale_(timecode_scale), | |
| 15 track_type_(-1), | |
| 16 track_num_(-1), | |
| 17 track_default_duration_(-1), | |
| 18 audio_track_num_(-1), | |
| 19 audio_default_duration_(base::TimeDelta::FromMicroseconds(-1)), | |
| 20 video_track_num_(-1), | |
| 21 video_default_duration_(base::TimeDelta::FromMicroseconds(-1)) { | |
| 22 } | |
| 23 | |
| 24 WebMTracksParser::~WebMTracksParser() {} | |
| 25 | |
| 26 int WebMTracksParser::Parse(const uint8* buf, int size) { | |
| 27 return WebMParseListElement(buf, size, kWebMIdTracks, 1, this); | |
| 28 } | |
| 29 | |
| 30 int64 WebMTracksParser::audio_track_num() const { | |
| 31 return audio_track_num_; | |
| 32 } | |
| 33 | |
| 34 base::TimeDelta WebMTracksParser::audio_default_duration() const { | |
| 35 return audio_default_duration_; | |
| 36 } | |
| 37 | |
| 38 int64 WebMTracksParser::video_track_num() const { | |
| 39 return video_track_num_; | |
| 40 } | |
| 41 | |
| 42 base::TimeDelta WebMTracksParser::video_default_duration() const { | |
| 43 return video_default_duration_; | |
| 44 } | |
| 45 | |
| 46 bool WebMTracksParser::OnListStart(int id) { | |
| 47 if (id == kWebMIdTrackEntry) { | |
| 48 track_type_ = -1; | |
| 49 track_num_ = -1; | |
| 50 track_default_duration_ = -1; | |
| 51 } | |
| 52 | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 bool WebMTracksParser::OnListEnd(int id) { | |
| 57 if (id == kWebMIdTrackEntry) { | |
| 58 if (track_type_ == -1 || track_num_ == -1) { | |
| 59 VLOG(1) << "Missing TrackEntry data" | |
| 60 << " TrackType " << track_type_ | |
|
scherkus (not reviewing)
2011/06/24 18:27:37
indentation
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
| |
| 61 << " TrackNum " << track_num_; | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 // Convert nanoseconds to base::TimeDelta. | |
| 66 base::TimeDelta default_duration = base::TimeDelta::FromMicroseconds( | |
| 67 track_default_duration_ / 1000.0); | |
| 68 | |
| 69 if (track_type_ == kWebMTrackTypeVideo) { | |
| 70 video_track_num_ = track_num_; | |
| 71 video_default_duration_ = default_duration; | |
| 72 } else if (track_type_ == kWebMTrackTypeAudio) { | |
| 73 audio_track_num_ = track_num_; | |
| 74 audio_default_duration_ = default_duration; | |
| 75 } else { | |
| 76 VLOG(1) << "Unexpected TrackType " << track_type_; | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 track_type_ = -1; | |
| 81 track_num_ = -1; | |
| 82 } | |
| 83 | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 bool WebMTracksParser::OnUInt(int id, int64 val) { | |
| 88 int64* dst = NULL; | |
| 89 | |
| 90 switch (id) { | |
| 91 case kWebMIdTrackNumber: | |
| 92 dst = &track_num_; | |
| 93 break; | |
| 94 case kWebMIdTrackType: | |
| 95 dst = &track_type_; | |
| 96 break; | |
| 97 case kWebMIdDefaultDuration: | |
| 98 dst = &track_default_duration_; | |
| 99 break; | |
| 100 default: | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 if (*dst != -1) { | |
| 105 VLOG(1) << "Multiple values for id " << std::hex << id << " specified"; | |
| 106 return false; | |
| 107 } | |
| 108 | |
| 109 *dst = val; | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 113 bool WebMTracksParser::OnFloat(int id, double val) { | |
| 114 VLOG(1) << "Unexpected float for id" << std::hex << id; | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { | |
| 119 return true; | |
| 120 } | |
| 121 | |
| 122 bool WebMTracksParser::OnString(int id, const std::string& str) { | |
| 123 if (id != kWebMIdCodecID) | |
| 124 return false; | |
| 125 | |
| 126 if (str != "A_VORBIS" && str != "V_VP8") { | |
| 127 VLOG(1) << "Unexpected CodecID " << str; | |
| 128 return false; | |
| 129 } | |
| 130 | |
| 131 return true; | |
| 132 } | |
| 133 | |
| 134 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags, | |
| 135 const uint8* data, int size) { | |
| 136 return false; | |
| 137 } | |
| 138 | |
| 139 } // namespace media | |
| OLD | NEW |