| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ffmpeg/ffmpeg_common.h" | 7 #include "media/ffmpeg/ffmpeg_common.h" |
| 8 #include "media/filters/ffmpeg_glue.h" | 8 #include "media/filters/ffmpeg_glue.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (new_offset < 0) | 74 if (new_offset < 0) |
| 75 new_offset = AVERROR_IO; | 75 new_offset = AVERROR_IO; |
| 76 return new_offset; | 76 return new_offset; |
| 77 } | 77 } |
| 78 | 78 |
| 79 int CloseContext(URLContext* h) { | 79 int CloseContext(URLContext* h) { |
| 80 h->priv_data = NULL; | 80 h->priv_data = NULL; |
| 81 return 0; | 81 return 0; |
| 82 } | 82 } |
| 83 | 83 |
| 84 int LockManagerOperation(void** lock, enum AVLockOp op) { |
| 85 switch (op) { |
| 86 case AV_LOCK_CREATE: |
| 87 *lock = new Lock(); |
| 88 if (!*lock) |
| 89 return 1; |
| 90 return 0; |
| 91 |
| 92 case AV_LOCK_OBTAIN: |
| 93 static_cast<Lock*>(*lock)->Acquire(); |
| 94 return 0; |
| 95 |
| 96 case AV_LOCK_RELEASE: |
| 97 static_cast<Lock*>(*lock)->Release(); |
| 98 return 0; |
| 99 |
| 100 case AV_LOCK_DESTROY: |
| 101 delete static_cast<Lock*>(*lock); |
| 102 *lock = NULL; |
| 103 return 0; |
| 104 } |
| 105 return 1; |
| 106 } |
| 107 |
| 84 } // namespace | 108 } // namespace |
| 85 | 109 |
| 86 //------------------------------------------------------------------------------ | 110 //------------------------------------------------------------------------------ |
| 87 | 111 |
| 88 namespace media { | 112 namespace media { |
| 89 | 113 |
| 90 // Use the HTTP protocol to avoid any file path separator issues. | 114 // Use the HTTP protocol to avoid any file path separator issues. |
| 91 static const char kProtocol[] = "http"; | 115 static const char kProtocol[] = "http"; |
| 92 | 116 |
| 93 // Fill out our FFmpeg protocol definition. | 117 // Fill out our FFmpeg protocol definition. |
| 94 static URLProtocol kFFmpegURLProtocol = { | 118 static URLProtocol kFFmpegURLProtocol = { |
| 95 kProtocol, | 119 kProtocol, |
| 96 &OpenContext, | 120 &OpenContext, |
| 97 &ReadContext, | 121 &ReadContext, |
| 98 &WriteContext, | 122 &WriteContext, |
| 99 &SeekContext, | 123 &SeekContext, |
| 100 &CloseContext, | 124 &CloseContext, |
| 101 }; | 125 }; |
| 102 | 126 |
| 103 FFmpegGlue::FFmpegGlue() { | 127 FFmpegGlue::FFmpegGlue() { |
| 104 // Before doing anything disable logging as it interferes with layout tests. | 128 // Before doing anything disable logging as it interferes with layout tests. |
| 105 av_log_set_level(AV_LOG_QUIET); | 129 av_log_set_level(AV_LOG_QUIET); |
| 106 | 130 |
| 107 // Register our protocol glue code with FFmpeg. | 131 // Register our protocol glue code with FFmpeg. |
| 108 avcodec_init(); | 132 avcodec_init(); |
| 109 av_register_protocol(&kFFmpegURLProtocol); | 133 av_register_protocol(&kFFmpegURLProtocol); |
| 134 av_lockmgr_register(&LockManagerOperation); |
| 110 | 135 |
| 111 // Now register the rest of FFmpeg. | 136 // Now register the rest of FFmpeg. |
| 112 av_register_all(); | 137 av_register_all(); |
| 113 } | 138 } |
| 114 | 139 |
| 115 FFmpegGlue::~FFmpegGlue() { | 140 FFmpegGlue::~FFmpegGlue() { |
| 141 av_lockmgr_register(NULL); |
| 116 } | 142 } |
| 117 | 143 |
| 118 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { | 144 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { |
| 119 AutoLock auto_lock(lock_); | 145 AutoLock auto_lock(lock_); |
| 120 std::string key = GetProtocolKey(protocol); | 146 std::string key = GetProtocolKey(protocol); |
| 121 if (protocols_.find(key) == protocols_.end()) { | 147 if (protocols_.find(key) == protocols_.end()) { |
| 122 protocols_[key] = protocol; | 148 protocols_[key] = protocol; |
| 123 } | 149 } |
| 124 return key; | 150 return key; |
| 125 } | 151 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 148 } | 174 } |
| 149 | 175 |
| 150 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 176 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
| 151 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 177 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
| 152 // This also has the nice property that adding the same FFmpegURLProtocol | 178 // This also has the nice property that adding the same FFmpegURLProtocol |
| 153 // reference will not generate duplicate entries. | 179 // reference will not generate duplicate entries. |
| 154 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 180 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
| 155 } | 181 } |
| 156 | 182 |
| 157 } // namespace media | 183 } // namespace media |
| OLD | NEW |