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 |
| 12 WebMTracksParser::WebMTracksParser(int64 timecode_scale) |
| 13 : timecode_scale_(timecode_scale), |
| 14 track_type_(-1), |
| 15 track_num_(-1), |
| 16 track_default_duration_(-1), |
| 17 audio_track_num_(-1), |
| 18 audio_default_duration_(base::TimeDelta::FromMicroseconds(-1)), |
| 19 video_track_num_(-1), |
| 20 video_default_duration_(base::TimeDelta::FromMicroseconds(-1)) { |
| 21 } |
| 22 |
| 23 WebMTracksParser::~WebMTracksParser() {} |
| 24 |
| 25 int WebMTracksParser::Parse(const uint8* buf, int size) { |
| 26 return WebMParseListElement(buf, size, kWebMIdTracks, 1, this); |
| 27 } |
| 28 |
| 29 |
| 30 bool WebMTracksParser::OnListStart(int id) { |
| 31 if (id == kWebMIdTrackEntry) { |
| 32 track_type_ = -1; |
| 33 track_num_ = -1; |
| 34 track_default_duration_ = -1; |
| 35 } |
| 36 |
| 37 return true; |
| 38 } |
| 39 |
| 40 bool WebMTracksParser::OnListEnd(int id) { |
| 41 if (id == kWebMIdTrackEntry) { |
| 42 if (track_type_ == -1 || track_num_ == -1) { |
| 43 VLOG(1) << "Missing TrackEntry data" |
| 44 << " TrackType " << track_type_ |
| 45 << " TrackNum " << track_num_; |
| 46 return false; |
| 47 } |
| 48 |
| 49 // Convert nanoseconds to base::TimeDelta. |
| 50 base::TimeDelta default_duration = base::TimeDelta::FromMicroseconds( |
| 51 track_default_duration_ / 1000.0); |
| 52 |
| 53 if (track_type_ == kWebMTrackTypeVideo) { |
| 54 video_track_num_ = track_num_; |
| 55 video_default_duration_ = default_duration; |
| 56 } else if (track_type_ == kWebMTrackTypeAudio) { |
| 57 audio_track_num_ = track_num_; |
| 58 audio_default_duration_ = default_duration; |
| 59 } else { |
| 60 VLOG(1) << "Unexpected TrackType " << track_type_; |
| 61 return false; |
| 62 } |
| 63 |
| 64 track_type_ = -1; |
| 65 track_num_ = -1; |
| 66 } |
| 67 |
| 68 return true; |
| 69 } |
| 70 |
| 71 bool WebMTracksParser::OnUInt(int id, int64 val) { |
| 72 int64* dst = NULL; |
| 73 |
| 74 switch (id) { |
| 75 case kWebMIdTrackNumber: |
| 76 dst = &track_num_; |
| 77 break; |
| 78 case kWebMIdTrackType: |
| 79 dst = &track_type_; |
| 80 break; |
| 81 case kWebMIdDefaultDuration: |
| 82 dst = &track_default_duration_; |
| 83 break; |
| 84 default: |
| 85 return true; |
| 86 } |
| 87 |
| 88 if (*dst != -1) { |
| 89 VLOG(1) << "Multiple values for id " << std::hex << id << " specified"; |
| 90 return false; |
| 91 } |
| 92 |
| 93 *dst = val; |
| 94 return true; |
| 95 } |
| 96 |
| 97 bool WebMTracksParser::OnFloat(int id, double val) { |
| 98 VLOG(1) << "Unexpected float for id" << std::hex << id; |
| 99 return false; |
| 100 } |
| 101 |
| 102 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { |
| 103 return true; |
| 104 } |
| 105 |
| 106 bool WebMTracksParser::OnString(int id, const std::string& str) { |
| 107 if (id != kWebMIdCodecID) |
| 108 return false; |
| 109 |
| 110 if (str != "A_VORBIS" && str != "V_VP8") { |
| 111 VLOG(1) << "Unexpected CodecID " << str; |
| 112 return false; |
| 113 } |
| 114 |
| 115 return true; |
| 116 } |
| 117 |
| 118 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags, |
| 119 const uint8* data, int size) { |
| 120 return false; |
| 121 } |
| 122 |
| 123 } // namespace media |
OLD | NEW |