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

Side by Side Diff: services/media/framework_ffmpeg/ffmpeg_video_decoder.cc

Issue 1686363002: Motown: ffmpeg implementations of framework 'parts' (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Retype some const unique_ptr<T>& parameters to const T&. Created 4 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/logging.h"
6 #include "services/media/framework_ffmpeg/ffmpeg_video_decoder.h"
7
8 namespace mojo {
9 namespace media {
10
11 FfmpegVideoDecoder::FfmpegVideoDecoder(AVCodecContext *av_codec_context) :
12 FfmpegDecoderBase(av_codec_context) {
13 DCHECK(av_codec_context_);
14 }
15
16 FfmpegVideoDecoder::~FfmpegVideoDecoder() {}
17
18 int FfmpegVideoDecoder::Decode(
19 PayloadAllocator* allocator,
20 bool* frame_decoded_out) {
21 DCHECK(allocator);
22 DCHECK(frame_decoded_out);
23 DCHECK(av_codec_context_);
24 DCHECK(av_frame_);
25
26 int frame_decoded = 0;
27 int input_bytes_used = avcodec_decode_video2(
28 av_codec_context_.get(),
29 av_frame_.get(),
30 &frame_decoded,
31 &av_packet_);
32 *frame_decoded_out = frame_decoded != 0;
33 return input_bytes_used;
34 }
35
36 PacketPtr FfmpegVideoDecoder::CreateOutputPacket(PayloadAllocator* allocator) {
37 DCHECK(allocator);
38 DCHECK(av_frame_);
39
40 // End of stream is indicated when we're draining and produce no packet.
41 // TODO(dalesat): This is just a copy of the audio version.
42 return Packet::Create(
43 av_frame_->pts,
44 av_frame_->pkt_duration,
45 false,
46 packet_size_,
47 av_frame_->data[0],
48 allocator);
49 }
50
51 int FfmpegVideoDecoder::AllocateBufferForAvFrame(
52 AVCodecContext* av_codec_context,
53 AVFrame* av_frame,
54 int flags) {
55 // It's important to use av_codec_context here rather than av_codec_context_,
56 // because av_codec_context is different for different threads when we're
57 // decoding on multiple threads. If this code is moved to an instance method,
58 // be sure to avoid using av_codec_context_.
59
60 // TODO(dalesat): Not sure why/if this is needed.
61 //int result = av_image_check_size(
62 // av_codec_context->width,
63 // av_codec_context->height,
64 // 0,
65 // NULL);
66 //if (result < 0) {
67 // DCHECK(false) << "av_image_check_size failed";
68 // return result;
69 //}
70
71 // TODO(dalesat): Not sure why this is needed.
72 int coded_width =
73 std::max(av_codec_context->width, av_codec_context->coded_width);
74 int coded_height =
75 std::max(av_codec_context->height, av_codec_context->coded_height);
76 DCHECK_EQ(coded_width, av_codec_context->coded_width) <<
77 "coded width is less than width";
78 DCHECK_EQ(coded_height, av_codec_context->coded_height) <<
79 "coded height is less than height";
80
81 // TODO(dalesat): Fill in av_frame->data and av_frame->data for each plane.
82
83 av_frame->width = coded_width;
84 av_frame->height = coded_height;
85 av_frame->format = av_codec_context->pix_fmt;
86 av_frame->reordered_opaque = av_codec_context->reordered_opaque;
87
88 av_frame->buf[0] = av_buffer_create(
89 av_frame->data[0], // Because this is the first chunk in the buffer.
90 0, // TODO(dalesat): Provide this.
91 ReleaseBufferForAvFrame,
92 nullptr, // opaque
93 0); // flags
94
95 return 0;
96 }
97
98 void FfmpegVideoDecoder::ReleaseBufferForAvFrame(
99 void* opaque, uint8_t* buffer) {
100 // Nothing to do.
101 // TODO(dalesat): Can we get rid of this method altogether?
102 }
103
104 } // namespace media
105 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698