| 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/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "media/base/filters.h" | 6 #include "media/base/filters.h" |
| 7 #include "media/filters/ffmpeg_common.h" | 7 #include "media/filters/ffmpeg_common.h" |
| 8 #include "media/filters/ffmpeg_glue.h" | 8 #include "media/filters/ffmpeg_glue.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 media::FFmpegURLProtocol* ToProtocol(void* data) { | 12 media::FFmpegURLProtocol* ToProtocol(void* data) { |
| 13 return reinterpret_cast<media::FFmpegURLProtocol*>(data); | 13 return reinterpret_cast<media::FFmpegURLProtocol*>(data); |
| 14 } | 14 } |
| 15 | 15 |
| 16 // FFmpeg protocol interface. | 16 // FFmpeg protocol interface. |
| 17 int OpenContext(URLContext* h, const char* filename, int flags) { | 17 int OpenContext(URLContext* h, const char* filename, int flags) { |
| 18 media::FFmpegURLProtocol* protocol; | 18 media::FFmpegURLProtocol* protocol; |
| 19 media::FFmpegGlue::get()->GetProtocol(filename, &protocol); | 19 media::FFmpegGlue::get()->GetProtocol(filename, &protocol); |
| 20 if (!protocol) | 20 if (!protocol) |
| 21 return AVERROR_IO; | 21 return AVERROR_IO; |
| 22 | 22 |
| 23 h->priv_data = protocol; | 23 h->priv_data = protocol; |
| 24 h->flags = URL_RDONLY; | 24 h->flags = URL_RDONLY; |
| 25 h->is_streamed = protocol->IsStreamed(); | 25 h->is_streamed = protocol->IsStreaming(); |
| 26 return 0; | 26 return 0; |
| 27 } | 27 } |
| 28 | 28 |
| 29 int ReadContext(URLContext* h, unsigned char* buf, int size) { | 29 int ReadContext(URLContext* h, unsigned char* buf, int size) { |
| 30 media::FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 30 media::FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
| 31 int result = protocol->Read(size, buf); | 31 int result = protocol->Read(size, buf); |
| 32 if (result < 0) | 32 if (result < 0) |
| 33 result = AVERROR_IO; | 33 result = AVERROR_IO; |
| 34 return result; | 34 return result; |
| 35 } | 35 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 145 } |
| 146 | 146 |
| 147 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 147 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
| 148 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 148 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
| 149 // This also has the nice property that adding the same FFmpegURLProtocol | 149 // This also has the nice property that adding the same FFmpegURLProtocol |
| 150 // reference will not generate duplicate entries. | 150 // reference will not generate duplicate entries. |
| 151 return StringPrintf("%s://0x%lx", kProtocol, static_cast<void*>(protocol)); | 151 return StringPrintf("%s://0x%lx", kProtocol, static_cast<void*>(protocol)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace media | 154 } // namespace media |
| OLD | NEW |