| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
| 6 #include "base/stl_util-inl.h" | 6 #include "base/stl_util-inl.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "media/base/filter_host.h" | 9 #include "media/base/filter_host.h" |
| 10 #include "media/filters/ffmpeg_common.h" | 10 #include "media/filters/ffmpeg_common.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 306 |
| 307 // Open FFmpeg AVFormatContext. | 307 // Open FFmpeg AVFormatContext. |
| 308 DCHECK(!format_context_); | 308 DCHECK(!format_context_); |
| 309 AVFormatContext* context = NULL; | 309 AVFormatContext* context = NULL; |
| 310 int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL); | 310 int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL); |
| 311 | 311 |
| 312 // Remove our data source. | 312 // Remove our data source. |
| 313 FFmpegGlue::get()->RemoveDataSource(data_source); | 313 FFmpegGlue::get()->RemoveDataSource(data_source); |
| 314 | 314 |
| 315 if (result < 0) { | 315 if (result < 0) { |
| 316 host()->Error(DEMUXER_ERROR_COULD_NOT_OPEN); | 316 host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN); |
| 317 callback->Run(); | 317 callback->Run(); |
| 318 return; | 318 return; |
| 319 } | 319 } |
| 320 | 320 |
| 321 DCHECK(context); | 321 DCHECK(context); |
| 322 format_context_ = context; | 322 format_context_ = context; |
| 323 | 323 |
| 324 // Serialize calls to av_find_stream_info(). | 324 // Serialize calls to av_find_stream_info(). |
| 325 { | 325 { |
| 326 AutoLock auto_lock(FFmpegLock::get()->lock()); | 326 AutoLock auto_lock(FFmpegLock::get()->lock()); |
| 327 | 327 |
| 328 // Fully initialize AVFormatContext by parsing the stream a little. | 328 // Fully initialize AVFormatContext by parsing the stream a little. |
| 329 result = av_find_stream_info(format_context_); | 329 result = av_find_stream_info(format_context_); |
| 330 if (result < 0) { | 330 if (result < 0) { |
| 331 host()->Error(DEMUXER_ERROR_COULD_NOT_PARSE); | 331 host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE); |
| 332 callback->Run(); | 332 callback->Run(); |
| 333 return; | 333 return; |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 // Create demuxer streams for all supported streams. | 337 // Create demuxer streams for all supported streams. |
| 338 base::TimeDelta max_duration; | 338 base::TimeDelta max_duration; |
| 339 for (size_t i = 0; i < format_context_->nb_streams; ++i) { | 339 for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
| 340 CodecType codec_type = format_context_->streams[i]->codec->codec_type; | 340 CodecType codec_type = format_context_->streams[i]->codec->codec_type; |
| 341 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { | 341 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { |
| 342 AVStream* stream = format_context_->streams[i]; | 342 AVStream* stream = format_context_->streams[i]; |
| 343 FFmpegDemuxerStream* demuxer_stream | 343 FFmpegDemuxerStream* demuxer_stream |
| 344 = new FFmpegDemuxerStream(this, stream); | 344 = new FFmpegDemuxerStream(this, stream); |
| 345 DCHECK(demuxer_stream); | 345 DCHECK(demuxer_stream); |
| 346 streams_.push_back(demuxer_stream); | 346 streams_.push_back(demuxer_stream); |
| 347 packet_streams_.push_back(demuxer_stream); | 347 packet_streams_.push_back(demuxer_stream); |
| 348 max_duration = std::max(max_duration, demuxer_stream->duration()); | 348 max_duration = std::max(max_duration, demuxer_stream->duration()); |
| 349 } else { | 349 } else { |
| 350 packet_streams_.push_back(NULL); | 350 packet_streams_.push_back(NULL); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 if (streams_.empty()) { | 353 if (streams_.empty()) { |
| 354 host()->Error(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 354 host()->SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
| 355 callback->Run(); | 355 callback->Run(); |
| 356 return; | 356 return; |
| 357 } | 357 } |
| 358 | 358 |
| 359 // Good to go: set the duration and notify we're done initializing. | 359 // Good to go: set the duration and notify we're done initializing. |
| 360 host()->SetDuration(max_duration); | 360 host()->SetDuration(max_duration); |
| 361 callback->Run(); | 361 callback->Run(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void FFmpegDemuxer::SeekTask(base::TimeDelta time, FilterCallback* callback) { | 364 void FFmpegDemuxer::SeekTask(base::TimeDelta time, FilterCallback* callback) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 DCHECK_EQ(MessageLoop::current(), message_loop()); | 467 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 468 StreamVector::iterator iter; | 468 StreamVector::iterator iter; |
| 469 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 469 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
| 470 AVPacket* packet = new AVPacket(); | 470 AVPacket* packet = new AVPacket(); |
| 471 memset(packet, 0, sizeof(*packet)); | 471 memset(packet, 0, sizeof(*packet)); |
| 472 (*iter)->EnqueuePacket(packet); | 472 (*iter)->EnqueuePacket(packet); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace media | 476 } // namespace media |
| OLD | NEW |