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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 MPEGAudioStreamParserBase::~MPEGAudioStreamParserBase() {} | 55 MPEGAudioStreamParserBase::~MPEGAudioStreamParserBase() {} |
56 | 56 |
57 void MPEGAudioStreamParserBase::Init( | 57 void MPEGAudioStreamParserBase::Init( |
58 const InitCB& init_cb, | 58 const InitCB& init_cb, |
59 const NewConfigCB& config_cb, | 59 const NewConfigCB& config_cb, |
60 const NewBuffersCB& new_buffers_cb, | 60 const NewBuffersCB& new_buffers_cb, |
61 bool ignore_text_tracks, | 61 bool ignore_text_tracks, |
62 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 62 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
63 const NewMediaSegmentCB& new_segment_cb, | 63 const NewMediaSegmentCB& new_segment_cb, |
64 const base::Closure& end_of_segment_cb, | 64 const base::Closure& end_of_segment_cb, |
65 const LogCB& log_cb) { | 65 const scoped_refptr<MediaLog>& media_log) { |
66 DVLOG(1) << __FUNCTION__; | 66 DVLOG(1) << __FUNCTION__; |
67 DCHECK_EQ(state_, UNINITIALIZED); | 67 DCHECK_EQ(state_, UNINITIALIZED); |
68 init_cb_ = init_cb; | 68 init_cb_ = init_cb; |
69 config_cb_ = config_cb; | 69 config_cb_ = config_cb; |
70 new_buffers_cb_ = new_buffers_cb; | 70 new_buffers_cb_ = new_buffers_cb; |
71 new_segment_cb_ = new_segment_cb; | 71 new_segment_cb_ = new_segment_cb; |
72 end_of_segment_cb_ = end_of_segment_cb; | 72 end_of_segment_cb_ = end_of_segment_cb; |
73 log_cb_ = log_cb; | 73 media_log_ = media_log; |
74 | 74 |
75 ChangeState(INITIALIZED); | 75 ChangeState(INITIALIZED); |
76 } | 76 } |
77 | 77 |
78 void MPEGAudioStreamParserBase::Flush() { | 78 void MPEGAudioStreamParserBase::Flush() { |
79 DVLOG(1) << __FUNCTION__; | 79 DVLOG(1) << __FUNCTION__; |
80 DCHECK_NE(state_, UNINITIALIZED); | 80 DCHECK_NE(state_, UNINITIALIZED); |
81 queue_.Reset(); | 81 queue_.Reset(); |
82 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); | 82 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); |
83 in_media_segment_ = false; | 83 in_media_segment_ = false; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (size < 4) | 255 if (size < 4) |
256 return 0; | 256 return 0; |
257 | 257 |
258 if (memcmp("ICY ", data, 4)) | 258 if (memcmp("ICY ", data, 4)) |
259 return -1; | 259 return -1; |
260 | 260 |
261 int locate_size = std::min(size, kMaxIcecastHeaderSize); | 261 int locate_size = std::min(size, kMaxIcecastHeaderSize); |
262 int offset = LocateEndOfHeaders(data, locate_size, 4); | 262 int offset = LocateEndOfHeaders(data, locate_size, 4); |
263 if (offset < 0) { | 263 if (offset < 0) { |
264 if (locate_size == kMaxIcecastHeaderSize) { | 264 if (locate_size == kMaxIcecastHeaderSize) { |
265 MEDIA_LOG(ERROR, log_cb_) << "Icecast header is too large."; | 265 MEDIA_LOG(ERROR, media_log_) << "Icecast header is too large."; |
266 return -1; | 266 return -1; |
267 } | 267 } |
268 | 268 |
269 return 0; | 269 return 0; |
270 } | 270 } |
271 | 271 |
272 return offset; | 272 return offset; |
273 } | 273 } |
274 | 274 |
275 int MPEGAudioStreamParserBase::ParseID3v1(const uint8* data, int size) { | 275 int MPEGAudioStreamParserBase::ParseID3v1(const uint8* data, int size) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // expose it as a metadata text track. | 316 // expose it as a metadata text track. |
317 return actual_tag_size; | 317 return actual_tag_size; |
318 } | 318 } |
319 | 319 |
320 bool MPEGAudioStreamParserBase::ParseSyncSafeInt(BitReader* reader, | 320 bool MPEGAudioStreamParserBase::ParseSyncSafeInt(BitReader* reader, |
321 int32* value) { | 321 int32* value) { |
322 *value = 0; | 322 *value = 0; |
323 for (int i = 0; i < 4; ++i) { | 323 for (int i = 0; i < 4; ++i) { |
324 uint8 tmp; | 324 uint8 tmp; |
325 if (!reader->ReadBits(1, &tmp) || tmp != 0) { | 325 if (!reader->ReadBits(1, &tmp) || tmp != 0) { |
326 MEDIA_LOG(ERROR, log_cb_) << "ID3 syncsafe integer byte MSb is not 0!"; | 326 MEDIA_LOG(ERROR, media_log_) << "ID3 syncsafe integer byte MSb is not 0!"; |
327 return false; | 327 return false; |
328 } | 328 } |
329 | 329 |
330 if (!reader->ReadBits(7, &tmp)) | 330 if (!reader->ReadBits(7, &tmp)) |
331 return false; | 331 return false; |
332 | 332 |
333 *value <<= 7; | 333 *value <<= 7; |
334 *value += tmp; | 334 *value += tmp; |
335 } | 335 } |
336 | 336 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if (end_of_segment) { | 411 if (end_of_segment) { |
412 in_media_segment_ = false; | 412 in_media_segment_ = false; |
413 end_of_segment_cb_.Run(); | 413 end_of_segment_cb_.Run(); |
414 } | 414 } |
415 | 415 |
416 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); | 416 timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); |
417 return true; | 417 return true; |
418 } | 418 } |
419 | 419 |
420 } // namespace media | 420 } // namespace media |
OLD | NEW |