| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_video_decoder.h" | 5 #include "media/filters/ffmpeg_video_decoder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 static int GetVideoBufferImpl(struct AVCodecContext* s, | 97 static int GetVideoBufferImpl(struct AVCodecContext* s, |
| 98 AVFrame* frame, | 98 AVFrame* frame, |
| 99 int flags) { | 99 int flags) { |
| 100 FFmpegVideoDecoder* decoder = static_cast<FFmpegVideoDecoder*>(s->opaque); | 100 FFmpegVideoDecoder* decoder = static_cast<FFmpegVideoDecoder*>(s->opaque); |
| 101 return decoder->GetVideoBuffer(s, frame, flags); | 101 return decoder->GetVideoBuffer(s, frame, flags); |
| 102 } | 102 } |
| 103 | 103 |
| 104 static void ReleaseVideoBufferImpl(void* opaque, uint8_t* data) { | 104 static void ReleaseVideoBufferImpl(void* opaque, uint8_t* data) { |
| 105 scoped_refptr<VideoFrame> video_frame; | 105 if (opaque) |
| 106 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque)); | 106 static_cast<VideoFrame*>(opaque)->Release(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // static | 109 // static |
| 110 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) { | 110 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) { |
| 111 FFmpegGlue::InitializeFFmpeg(); | 111 FFmpegGlue::InitializeFFmpeg(); |
| 112 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr; | 112 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 FFmpegVideoDecoder::FFmpegVideoDecoder() | 115 FFmpegVideoDecoder::FFmpegVideoDecoder() |
| 116 : state_(kUninitialized), decode_nalus_(false) { | 116 : state_(kUninitialized), decode_nalus_(false) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 frame->linesize[i] = video_frame->stride(i); | 199 frame->linesize[i] = video_frame->stride(i); |
| 200 } | 200 } |
| 201 | 201 |
| 202 frame->width = coded_size.width(); | 202 frame->width = coded_size.width(); |
| 203 frame->height = coded_size.height(); | 203 frame->height = coded_size.height(); |
| 204 frame->format = codec_context->pix_fmt; | 204 frame->format = codec_context->pix_fmt; |
| 205 frame->reordered_opaque = codec_context->reordered_opaque; | 205 frame->reordered_opaque = codec_context->reordered_opaque; |
| 206 | 206 |
| 207 // Now create an AVBufferRef for the data just allocated. It will own the | 207 // Now create an AVBufferRef for the data just allocated. It will own the |
| 208 // reference to the VideoFrame object. | 208 // reference to the VideoFrame object. |
| 209 void* opaque = NULL; | 209 VideoFrame* opaque = video_frame.get(); |
| 210 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque)); | 210 opaque->AddRef(); |
| 211 frame->buf[0] = | 211 frame->buf[0] = |
| 212 av_buffer_create(frame->data[0], | 212 av_buffer_create(frame->data[0], |
| 213 VideoFrame::AllocationSize(format, coded_size), | 213 VideoFrame::AllocationSize(format, coded_size), |
| 214 ReleaseVideoBufferImpl, | 214 ReleaseVideoBufferImpl, |
| 215 opaque, | 215 opaque, |
| 216 0); | 216 0); |
| 217 return 0; | 217 return 0; |
| 218 } | 218 } |
| 219 | 219 |
| 220 std::string FFmpegVideoDecoder::GetDisplayName() const { | 220 std::string FFmpegVideoDecoder::GetDisplayName() const { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 428 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
| 429 ReleaseFFmpegResources(); | 429 ReleaseFFmpegResources(); |
| 430 return false; | 430 return false; |
| 431 } | 431 } |
| 432 | 432 |
| 433 av_frame_.reset(av_frame_alloc()); | 433 av_frame_.reset(av_frame_alloc()); |
| 434 return true; | 434 return true; |
| 435 } | 435 } |
| 436 | 436 |
| 437 } // namespace media | 437 } // namespace media |
| OLD | NEW |