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

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: Changed the way AVBuffer allocation/deallocation is done in the ffmpeg audio decoder. 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(AvCodecContextPtr av_codec_context) :
12 FfmpegDecoderBase(std::move(av_codec_context)) {
13 DCHECK(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(context());
24 DCHECK(frame());
25
26 int frame_decoded = 0;
27 int input_bytes_used = avcodec_decode_video2(
28 context().get(),
29 frame().get(),
30 &frame_decoded,
31 &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(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 frame()->pts,
44 frame()->pkt_duration,
45 false,
46 packet_size_,
47 frame()->data[0],
48 allocator);
49 }
50
51 PacketPtr FfmpegVideoDecoder::CreateOutputEndOfStreamPacket() {
52 // TODO(dalesat): Presentation time for this packet.
53 return Packet::CreateEndOfStream(0);
54 }
55
56 int FfmpegVideoDecoder::AllocateBufferForAvFrame(
57 AVCodecContext* av_codec_context,
58 AVFrame* av_frame,
59 int flags) {
60 // It's important to use av_codec_context here rather than context(),
61 // because av_codec_context is different for different threads when we're
62 // decoding on multiple threads. If this code is moved to an instance method,
63 // be sure to avoid using context().
64
65 // TODO(dalesat): Not sure why/if this is needed.
66 //int result = av_image_check_size(
67 // av_codec_context->width,
68 // av_codec_context->height,
69 // 0,
70 // NULL);
71 //if (result < 0) {
72 // DCHECK(false) << "av_image_check_size failed";
73 // return result;
74 //}
75
76 // TODO(dalesat): Not sure why this is needed.
77 int coded_width =
78 std::max(av_codec_context->width, av_codec_context->coded_width);
79 int coded_height =
80 std::max(av_codec_context->height, av_codec_context->coded_height);
81 DCHECK_EQ(coded_width, av_codec_context->coded_width) <<
82 "coded width is less than width";
83 DCHECK_EQ(coded_height, av_codec_context->coded_height) <<
84 "coded height is less than height";
85
86 // TODO(dalesat): Fill in av_frame->data and av_frame->data for each plane.
87
88 av_frame->width = coded_width;
89 av_frame->height = coded_height;
90 av_frame->format = av_codec_context->pix_fmt;
91 av_frame->reordered_opaque = av_codec_context->reordered_opaque;
92
93 av_frame->buf[0] = av_buffer_create(
94 av_frame->data[0], // Because this is the first chunk in the buffer.
95 0, // TODO(dalesat): Provide this.
96 ReleaseBufferForAvFrame,
97 nullptr, // opaque
98 0); // flags
99
100 return 0;
101 }
102
103 void FfmpegVideoDecoder::ReleaseBufferForAvFrame(
104 void* opaque, uint8_t* buffer) {
105 // Nothing to do.
106 // TODO(dalesat): Can we get rid of this method altogether?
107 }
108
109 } // namespace media
110 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698