| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/filters/ffmpeg_glue.h" | 5 #include "media/filters/ffmpeg_glue.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "media/base/filters.h" | 9 #include "media/base/filters.h" |
| 10 #include "media/ffmpeg/ffmpeg_common.h" | 10 #include "media/ffmpeg/ffmpeg_common.h" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 static FFmpegURLProtocol* ToProtocol(void* data) { | 14 static FFmpegURLProtocol* ToProtocol(void* data) { |
| 15 return reinterpret_cast<FFmpegURLProtocol*>(data); | 15 return reinterpret_cast<FFmpegURLProtocol*>(data); |
| 16 } | 16 } |
| 17 | 17 |
| 18 // FFmpeg protocol interface. | 18 // FFmpeg protocol interface. |
| 19 static int OpenContext(URLContext* h, const char* filename, int flags) { | 19 static int OpenContext(URLContext* h, const char* filename, int flags) { |
| 20 FFmpegURLProtocol* protocol; | 20 FFmpegURLProtocol* protocol; |
| 21 FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); | 21 FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); |
| 22 if (!protocol) | 22 if (!protocol) |
| 23 return AVERROR(EIO); | 23 return AVERROR(EIO); |
| 24 | 24 |
| 25 h->priv_data = protocol; | 25 h->priv_data = protocol; |
| 26 h->flags = URL_RDONLY; | 26 h->flags = AVIO_FLAG_READ; |
| 27 h->is_streamed = protocol->IsStreaming(); | 27 h->is_streamed = protocol->IsStreaming(); |
| 28 return 0; | 28 return 0; |
| 29 } | 29 } |
| 30 | 30 |
| 31 static int ReadContext(URLContext* h, unsigned char* buf, int size) { | 31 static int ReadContext(URLContext* h, unsigned char* buf, int size) { |
| 32 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 32 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
| 33 int result = protocol->Read(size, buf); | 33 int result = protocol->Read(size, buf); |
| 34 if (result < 0) | 34 if (result < 0) |
| 35 result = AVERROR(EIO); | 35 result = AVERROR(EIO); |
| 36 return result; | 36 return result; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return 1; | 111 return 1; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Use the HTTP protocol to avoid any file path separator issues. | 114 // Use the HTTP protocol to avoid any file path separator issues. |
| 115 static const char kProtocol[] = "http"; | 115 static const char kProtocol[] = "http"; |
| 116 | 116 |
| 117 // Fill out our FFmpeg protocol definition. | 117 // Fill out our FFmpeg protocol definition. |
| 118 static URLProtocol kFFmpegURLProtocol = { | 118 static URLProtocol kFFmpegURLProtocol = { |
| 119 kProtocol, | 119 kProtocol, |
| 120 &OpenContext, | 120 &OpenContext, |
| 121 NULL, // url_open2 |
| 121 &ReadContext, | 122 &ReadContext, |
| 122 &WriteContext, | 123 &WriteContext, |
| 123 &SeekContext, | 124 &SeekContext, |
| 124 &CloseContext, | 125 &CloseContext, |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 FFmpegGlue::FFmpegGlue() { | 128 FFmpegGlue::FFmpegGlue() { |
| 128 // Before doing anything disable logging as it interferes with layout tests. | 129 // Before doing anything disable logging as it interferes with layout tests. |
| 129 av_log_set_level(AV_LOG_QUIET); | 130 av_log_set_level(AV_LOG_QUIET); |
| 130 | 131 |
| 131 // Register our protocol glue code with FFmpeg. | 132 // Register our protocol glue code with FFmpeg. |
| 132 avcodec_init(); | 133 ffurl_register_protocol(&kFFmpegURLProtocol, sizeof(kFFmpegURLProtocol)); |
| 133 av_register_protocol2(&kFFmpegURLProtocol, sizeof(kFFmpegURLProtocol)); | |
| 134 av_lockmgr_register(&LockManagerOperation); | 134 av_lockmgr_register(&LockManagerOperation); |
| 135 | 135 |
| 136 // Now register the rest of FFmpeg. | 136 // Now register the rest of FFmpeg. |
| 137 av_register_all(); | 137 av_register_all(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 FFmpegGlue::~FFmpegGlue() { | 140 FFmpegGlue::~FFmpegGlue() { |
| 141 av_lockmgr_register(NULL); | 141 av_lockmgr_register(NULL); |
| 142 } | 142 } |
| 143 | 143 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 186 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
| 187 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 187 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
| 188 // This also has the nice property that adding the same FFmpegURLProtocol | 188 // This also has the nice property that adding the same FFmpegURLProtocol |
| 189 // reference will not generate duplicate entries. | 189 // reference will not generate duplicate entries. |
| 190 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 190 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 } // namespace media | 193 } // namespace media |
| OLD | NEW |