Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: media/filters/ffmpeg_glue.cc

Issue 7203002: Adding ChunkDemuxer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup & commenting Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // Register our protocol glue code with FFmpeg. 131 // Register our protocol glue code with FFmpeg.
132 avcodec_init(); 132 avcodec_init();
133 av_register_protocol2(&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 BufferUrlProtocol::BufferUrlProtocol(const uint8* buf, int size,
141 bool streaming)
142 : buf_(buf),
143 size_(size),
144 offset_(0),
145 streaming_(streaming) {
146 }
147
148 BufferUrlProtocol::~BufferUrlProtocol() {}
149
150 int BufferUrlProtocol::Read(int size, uint8* data) {
151 int bytes_to_copy = size;
152 int bytes_left = size_ - offset_;
153
154 if (bytes_to_copy > bytes_left)
155 bytes_to_copy = bytes_left;
156
157 if (bytes_to_copy == 0)
158 return 0;
159
160 memcpy(data, buf_ + offset_, bytes_to_copy);
161 offset_ += bytes_to_copy;
162
163 return bytes_to_copy;
164 }
165
166 bool BufferUrlProtocol::GetPosition(int64* position_out) {
167 *position_out = offset_;
168 return true;
169 }
170
171 bool BufferUrlProtocol::SetPosition(int64 position) {
172 if (position < 0 || position >= size_)
173 return false;
174
175 offset_ = position;
176 return true;
177 }
178
179 bool BufferUrlProtocol::GetSize(int64* size_out) {
180 *size_out = size_;
181 return true;
182 }
183
184 bool BufferUrlProtocol::IsStreaming() { return streaming_; }
185
186
140 FFmpegGlue::~FFmpegGlue() { 187 FFmpegGlue::~FFmpegGlue() {
141 av_lockmgr_register(NULL); 188 av_lockmgr_register(NULL);
142 } 189 }
143 190
144 // static 191 // static
145 FFmpegGlue* FFmpegGlue::GetInstance() { 192 FFmpegGlue* FFmpegGlue::GetInstance() {
146 return Singleton<FFmpegGlue>::get(); 193 return Singleton<FFmpegGlue>::get();
147 } 194 }
148 195
149 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) { 196 std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) {
(...skipping 29 matching lines...) Expand all
179 } 226 }
180 227
181 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { 228 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) {
182 // Use the FFmpegURLProtocol's memory address to generate the unique string. 229 // Use the FFmpegURLProtocol's memory address to generate the unique string.
183 // This also has the nice property that adding the same FFmpegURLProtocol 230 // This also has the nice property that adding the same FFmpegURLProtocol
184 // reference will not generate duplicate entries. 231 // reference will not generate duplicate entries.
185 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); 232 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol));
186 } 233 }
187 234
188 } // namespace media 235 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698