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 | |
108 } // namespace | 84 } // namespace |
109 | 85 |
110 //------------------------------------------------------------------------------ | 86 //------------------------------------------------------------------------------ |
111 | 87 |
112 namespace media { | 88 namespace media { |
113 | 89 |
114 // Use the HTTP protocol to avoid any file path separator issues. | 90 // Use the HTTP protocol to avoid any file path separator issues. |
115 static const char kProtocol[] = "http"; | 91 static const char kProtocol[] = "http"; |
116 | 92 |
117 // Fill out our FFmpeg protocol definition. | 93 // Fill out our FFmpeg protocol definition. |
118 static URLProtocol kFFmpegURLProtocol = { | 94 static URLProtocol kFFmpegURLProtocol = { |
119 kProtocol, | 95 kProtocol, |
120 &OpenContext, | 96 &OpenContext, |
121 &ReadContext, | 97 &ReadContext, |
122 &WriteContext, | 98 &WriteContext, |
123 &SeekContext, | 99 &SeekContext, |
124 &CloseContext, | 100 &CloseContext, |
125 }; | 101 }; |
126 | 102 |
127 FFmpegGlue::FFmpegGlue() { | 103 FFmpegGlue::FFmpegGlue() { |
128 // Before doing anything disable logging as it interferes with layout tests. | 104 // Before doing anything disable logging as it interferes with layout tests. |
129 av_log_set_level(AV_LOG_QUIET); | 105 av_log_set_level(AV_LOG_QUIET); |
130 | 106 |
131 // Register our protocol glue code with FFmpeg. | 107 // Register our protocol glue code with FFmpeg. |
132 avcodec_init(); | 108 avcodec_init(); |
133 av_register_protocol(&kFFmpegURLProtocol); | 109 av_register_protocol(&kFFmpegURLProtocol); |
134 av_lockmgr_register(&LockManagerOperation); | |
135 | 110 |
136 // Now register the rest of FFmpeg. | 111 // Now register the rest of FFmpeg. |
137 av_register_all(); | 112 av_register_all(); |
138 } | 113 } |
139 | 114 |
140 FFmpegGlue::~FFmpegGlue() { | 115 FFmpegGlue::~FFmpegGlue() { |
141 av_lockmgr_register(NULL); | |
142 } | 116 } |
143 | 117 |
144 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { | 118 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { |
145 AutoLock auto_lock(lock_); | 119 AutoLock auto_lock(lock_); |
146 std::string key = GetProtocolKey(protocol); | 120 std::string key = GetProtocolKey(protocol); |
147 if (protocols_.find(key) == protocols_.end()) { | 121 if (protocols_.find(key) == protocols_.end()) { |
148 protocols_[key] = protocol; | 122 protocols_[key] = protocol; |
149 } | 123 } |
150 return key; | 124 return key; |
151 } | 125 } |
(...skipping 22 matching lines...) Expand all Loading... |
174 } | 148 } |
175 | 149 |
176 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 150 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
177 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 151 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
178 // This also has the nice property that adding the same FFmpegURLProtocol | 152 // This also has the nice property that adding the same FFmpegURLProtocol |
179 // reference will not generate duplicate entries. | 153 // reference will not generate duplicate entries. |
180 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 154 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
181 } | 155 } |
182 | 156 |
183 } // namespace media | 157 } // namespace media |
OLD | NEW |