Chromium Code Reviews| Index: media/filters/ffmpeg_glue.cc |
| diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc |
| index e3b227b2ac5140f74f9057090d0bafdb26429961..9a7822e5ff51e72e77f1b283a8b16442623688c6 100644 |
| --- a/media/filters/ffmpeg_glue.cc |
| +++ b/media/filters/ffmpeg_glue.cc |
| @@ -6,7 +6,9 @@ |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| +#include "base/metrics/sparse_histogram.h" |
| #include "base/synchronization/lock.h" |
| +#include "media/base/container_names.h" |
| #include "media/ffmpeg/ffmpeg_common.h" |
| namespace media { |
| @@ -123,7 +125,8 @@ void FFmpegGlue::InitializeFFmpeg() { |
| } |
| FFmpegGlue::FFmpegGlue(FFmpegURLProtocol* protocol) |
| - : open_called_(false) { |
| + : open_called_(false), |
| + protocol_(protocol) { |
| InitializeFFmpeg(); |
| // Initialize an AVIOContext using our custom read and seek operations. Don't |
| @@ -155,6 +158,22 @@ bool FFmpegGlue::OpenContext() { |
| // destruction path to avoid double frees. |
| open_called_ = true; |
| + // Attempt to recognize the container by looking at the first few bytes of the |
| + // stream. The stream position is left unchanged. |
| + int64 pos; |
| + scoped_ptr<uint8[]> buffer(new uint8[8192]); |
| + |
| + protocol_->GetPosition(&pos); |
|
acolwell GONE FROM CHROMIUM
2013/05/18 01:22:09
nit: I think you can use avio_context_->opaque to
jrummell
2013/05/22 18:27:39
Done.
|
| + protocol_->SetPosition(0); |
| + int numRead = protocol_->Read(8192, buffer.get()); |
| + protocol_->SetPosition(pos); |
| + if (numRead > 0) { |
| + // < 0 means Read failed |
| + container_names::FFmpegContainerName container = |
| + container_names::DetermineContainer(buffer.get(), numRead); |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedContainer", container); |
| + } |
| + |
| // By passing NULL for the filename (second parameter) we are telling FFmpeg |
| // to use the AVIO context we setup from the AVFormatContext structure. |
| return avformat_open_input(&format_context_, NULL, NULL, NULL) == 0; |