| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/formats/mpeg/mpeg_audio_stream_parser_base.h" | 5 #include "media/formats/mpeg/mpeg_audio_stream_parser_base.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "media/base/media_log.h" | 12 #include "media/base/media_log.h" |
| 13 #include "media/base/media_tracks.h" | 13 #include "media/base/media_tracks.h" |
| 14 #include "media/base/media_util.h" | 14 #include "media/base/media_util.h" |
| 15 #include "media/base/stream_parser_buffer.h" | 15 #include "media/base/stream_parser_buffer.h" |
| 16 #include "media/base/text_track_config.h" | 16 #include "media/base/text_track_config.h" |
| 17 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
| 18 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 static const int kMpegAudioTrackId = 1; |
| 23 |
| 22 static const uint32_t kICYStartCode = 0x49435920; // 'ICY ' | 24 static const uint32_t kICYStartCode = 0x49435920; // 'ICY ' |
| 23 | 25 |
| 24 // Arbitrary upper bound on the size of an IceCast header before it | 26 // Arbitrary upper bound on the size of an IceCast header before it |
| 25 // triggers an error. | 27 // triggers an error. |
| 26 static const int kMaxIcecastHeaderSize = 4096; | 28 static const int kMaxIcecastHeaderSize = 4096; |
| 27 | 29 |
| 28 static const uint32_t kID3StartCodeMask = 0xffffff00; | 30 static const uint32_t kID3StartCodeMask = 0xffffff00; |
| 29 static const uint32_t kID3v1StartCode = 0x54414700; // 'TAG\0' | 31 static const uint32_t kID3v1StartCode = 0x54414700; // 'TAG\0' |
| 30 static const int kID3v1Size = 128; | 32 static const int kID3v1Size = 128; |
| 31 static const int kID3v1ExtendedSize = 227; | 33 static const int kID3v1ExtendedSize = 227; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 217 |
| 216 base::TimeDelta base_timestamp; | 218 base::TimeDelta base_timestamp; |
| 217 if (timestamp_helper_) | 219 if (timestamp_helper_) |
| 218 base_timestamp = timestamp_helper_->GetTimestamp(); | 220 base_timestamp = timestamp_helper_->GetTimestamp(); |
| 219 | 221 |
| 220 timestamp_helper_.reset(new AudioTimestampHelper(sample_rate)); | 222 timestamp_helper_.reset(new AudioTimestampHelper(sample_rate)); |
| 221 timestamp_helper_->SetBaseTimestamp(base_timestamp); | 223 timestamp_helper_->SetBaseTimestamp(base_timestamp); |
| 222 | 224 |
| 223 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); | 225 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); |
| 224 if (config_.IsValidConfig()) { | 226 if (config_.IsValidConfig()) { |
| 225 media_tracks->AddAudioTrack(config_, 1, "main", "", ""); | 227 media_tracks->AddAudioTrack(config_, kMpegAudioTrackId, "main", "", ""); |
| 226 } | 228 } |
| 227 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) | 229 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) |
| 228 return -1; | 230 return -1; |
| 229 | 231 |
| 230 if (!init_cb_.is_null()) { | 232 if (!init_cb_.is_null()) { |
| 231 InitParameters params(kInfiniteDuration); | 233 InitParameters params(kInfiniteDuration); |
| 232 params.detected_audio_track_count = 1; | 234 params.detected_audio_track_count = 1; |
| 233 params.auto_update_timestamp_offset = true; | 235 params.auto_update_timestamp_offset = true; |
| 234 base::ResetAndReturn(&init_cb_).Run(params); | 236 base::ResetAndReturn(&init_cb_).Run(params); |
| 235 } | 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 if (metadata_frame) | 240 if (metadata_frame) |
| 239 return frame_size; | 241 return frame_size; |
| 240 | 242 |
| 241 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId | 243 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId |
| 242 // type and allow multiple audio tracks, if applicable. See | 244 // type and allow multiple audio tracks, if applicable. See |
| 243 // https://crbug.com/341581. | 245 // https://crbug.com/341581. |
| 244 scoped_refptr<StreamParserBuffer> buffer = | 246 scoped_refptr<StreamParserBuffer> buffer = StreamParserBuffer::CopyFrom( |
| 245 StreamParserBuffer::CopyFrom(data, frame_size, true, | 247 data, frame_size, true, DemuxerStream::AUDIO, kMpegAudioTrackId); |
| 246 DemuxerStream::AUDIO, 0); | |
| 247 buffer->set_timestamp(timestamp_helper_->GetTimestamp()); | 248 buffer->set_timestamp(timestamp_helper_->GetTimestamp()); |
| 248 buffer->set_duration(timestamp_helper_->GetFrameDuration(sample_count)); | 249 buffer->set_duration(timestamp_helper_->GetFrameDuration(sample_count)); |
| 249 buffers->push_back(buffer); | 250 buffers->push_back(buffer); |
| 250 | 251 |
| 251 timestamp_helper_->AddFrames(sample_count); | 252 timestamp_helper_->AddFrames(sample_count); |
| 252 | 253 |
| 253 return frame_size; | 254 return frame_size; |
| 254 } | 255 } |
| 255 | 256 |
| 256 int MPEGAudioStreamParserBase::ParseIcecastHeader(const uint8_t* data, | 257 int MPEGAudioStreamParserBase::ParseIcecastHeader(const uint8_t* data, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (end_of_segment) { | 417 if (end_of_segment) { |
| 417 in_media_segment_ = false; | 418 in_media_segment_ = false; |
| 418 end_of_segment_cb_.Run(); | 419 end_of_segment_cb_.Run(); |
| 419 } | 420 } |
| 420 | 421 |
| 421 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); | 422 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); |
| 422 return true; | 423 return true; |
| 423 } | 424 } |
| 424 | 425 |
| 425 } // namespace media | 426 } // namespace media |
| OLD | NEW |