| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 int CloseContext(URLContext* h) { | 83 int CloseContext(URLContext* h) { |
| 84 h->priv_data = NULL; | 84 h->priv_data = NULL; |
| 85 return 0; | 85 return 0; |
| 86 } | 86 } |
| 87 | 87 |
| 88 int LockManagerOperation(void** lock, enum AVLockOp op) { | 88 int LockManagerOperation(void** lock, enum AVLockOp op) { |
| 89 switch (op) { | 89 switch (op) { |
| 90 case AV_LOCK_CREATE: | 90 case AV_LOCK_CREATE: |
| 91 *lock = new Lock(); | 91 *lock = new base::Lock(); |
| 92 if (!*lock) | 92 if (!*lock) |
| 93 return 1; | 93 return 1; |
| 94 return 0; | 94 return 0; |
| 95 | 95 |
| 96 case AV_LOCK_OBTAIN: | 96 case AV_LOCK_OBTAIN: |
| 97 static_cast<Lock*>(*lock)->Acquire(); | 97 static_cast<base::Lock*>(*lock)->Acquire(); |
| 98 return 0; | 98 return 0; |
| 99 | 99 |
| 100 case AV_LOCK_RELEASE: | 100 case AV_LOCK_RELEASE: |
| 101 static_cast<Lock*>(*lock)->Release(); | 101 static_cast<base::Lock*>(*lock)->Release(); |
| 102 return 0; | 102 return 0; |
| 103 | 103 |
| 104 case AV_LOCK_DESTROY: | 104 case AV_LOCK_DESTROY: |
| 105 delete static_cast<Lock*>(*lock); | 105 delete static_cast<base::Lock*>(*lock); |
| 106 *lock = NULL; | 106 *lock = NULL; |
| 107 return 0; | 107 return 0; |
| 108 } | 108 } |
| 109 return 1; | 109 return 1; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 //------------------------------------------------------------------------------ | 114 //------------------------------------------------------------------------------ |
| 115 | 115 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 144 FFmpegGlue::~FFmpegGlue() { | 144 FFmpegGlue::~FFmpegGlue() { |
| 145 av_lockmgr_register(NULL); | 145 av_lockmgr_register(NULL); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // static | 148 // static |
| 149 FFmpegGlue* FFmpegGlue::GetInstance() { | 149 FFmpegGlue* FFmpegGlue::GetInstance() { |
| 150 return Singleton<FFmpegGlue>::get(); | 150 return Singleton<FFmpegGlue>::get(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { | 153 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { |
| 154 AutoLock auto_lock(lock_); | 154 base::AutoLock auto_lock(lock_); |
| 155 std::string key = GetProtocolKey(protocol); | 155 std::string key = GetProtocolKey(protocol); |
| 156 if (protocols_.find(key) == protocols_.end()) { | 156 if (protocols_.find(key) == protocols_.end()) { |
| 157 protocols_[key] = protocol; | 157 protocols_[key] = protocol; |
| 158 } | 158 } |
| 159 return key; | 159 return key; |
| 160 } | 160 } |
| 161 | 161 |
| 162 void FFmpegGlue::RemoveProtocol(FFmpegURLProtocol* protocol) { | 162 void FFmpegGlue::RemoveProtocol(FFmpegURLProtocol* protocol) { |
| 163 AutoLock auto_lock(lock_); | 163 base::AutoLock auto_lock(lock_); |
| 164 for (ProtocolMap::iterator cur, iter = protocols_.begin(); | 164 for (ProtocolMap::iterator cur, iter = protocols_.begin(); |
| 165 iter != protocols_.end();) { | 165 iter != protocols_.end();) { |
| 166 cur = iter; | 166 cur = iter; |
| 167 iter++; | 167 iter++; |
| 168 | 168 |
| 169 if (cur->second == protocol) | 169 if (cur->second == protocol) |
| 170 protocols_.erase(cur); | 170 protocols_.erase(cur); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 void FFmpegGlue::GetProtocol(const std::string& key, | 174 void FFmpegGlue::GetProtocol(const std::string& key, |
| 175 FFmpegURLProtocol** protocol) { | 175 FFmpegURLProtocol** protocol) { |
| 176 AutoLock auto_lock(lock_); | 176 base::AutoLock auto_lock(lock_); |
| 177 ProtocolMap::iterator iter = protocols_.find(key); | 177 ProtocolMap::iterator iter = protocols_.find(key); |
| 178 if (iter == protocols_.end()) { | 178 if (iter == protocols_.end()) { |
| 179 *protocol = NULL; | 179 *protocol = NULL; |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 *protocol = iter->second; | 182 *protocol = iter->second; |
| 183 } | 183 } |
| 184 | 184 |
| 185 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 185 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
| 186 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 186 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
| 187 // This also has the nice property that adding the same FFmpegURLProtocol | 187 // This also has the nice property that adding the same FFmpegURLProtocol |
| 188 // reference will not generate duplicate entries. | 188 // reference will not generate duplicate entries. |
| 189 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 189 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace media | 192 } // namespace media |
| OLD | NEW |