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

Side by Side Diff: services/media/framework_ffmpeg/ffmpeg_decoder_base.h

Issue 1923763002: Motown: Ffmpeg video decoder (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Minor fixes per feedback. Created 4 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ 5 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_
6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_
7 7
8 #include "services/media/framework/parts/decoder.h" 8 #include "services/media/framework/parts/decoder.h"
9 #include "services/media/framework_ffmpeg/av_codec_context.h" 9 #include "services/media/framework_ffmpeg/av_codec_context.h"
10 #include "services/media/framework_ffmpeg/av_frame.h" 10 #include "services/media/framework_ffmpeg/av_frame.h"
(...skipping 17 matching lines...) Expand all
28 28
29 // Transform implementation. 29 // Transform implementation.
30 void Flush() override; 30 void Flush() override;
31 31
32 bool TransformPacket(const PacketPtr& input, 32 bool TransformPacket(const PacketPtr& input,
33 bool new_input, 33 bool new_input,
34 PayloadAllocator* allocator, 34 PayloadAllocator* allocator,
35 PacketPtr* output) override; 35 PacketPtr* output) override;
36 36
37 protected: 37 protected:
38 // Used to control deallocation of buffers.
39 class AvBufferContext {
40 public:
41 AvBufferContext(size_t size, PayloadAllocator* allocator)
42 : size_(size), allocator_(allocator) {
43 DCHECK(allocator_);
44 if (size_ == 0) {
45 buffer_ = nullptr;
46 } else {
47 buffer_ =
48 static_cast<uint8_t*>(allocator_->AllocatePayloadBuffer(size_));
49 }
50 }
51
52 ~AvBufferContext() {
53 if (allocator_ == nullptr) {
54 // Previously released.
55 return;
56 }
57
58 if (size_ != 0) {
59 DCHECK(buffer_ != nullptr);
60 allocator_->ReleasePayloadBuffer(size_, buffer_);
61 return;
62 }
63
64 DCHECK(buffer_ == nullptr);
65 }
66
67 uint8_t* buffer() { return buffer_; }
68
69 size_t size() { return size_; }
70
71 // Releases ownership of the buffer.
72 uint8_t* Release() {
73 DCHECK(allocator_) << "AvBufferContext released twice";
74 uint8_t* result = buffer_;
75 buffer_ = nullptr;
76 size_ = 0;
77 allocator_ = nullptr;
78 return result;
79 }
80
81 private:
82 uint8_t* buffer_;
83 size_t size_;
84 PayloadAllocator* allocator_;
85 };
86
38 // Decodes from av_packet into av_frame_ptr. The result indicates how many 87 // Decodes from av_packet into av_frame_ptr. The result indicates how many
39 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether 88 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether
40 // av_frame_ptr contains a complete frame. 89 // av_frame_ptr contains a complete frame.
41 virtual int Decode(const AVPacket& av_packet, 90 virtual int Decode(const AVPacket& av_packet,
42 const ffmpeg::AvFramePtr& av_frame_ptr, 91 const ffmpeg::AvFramePtr& av_frame_ptr,
43 PayloadAllocator* allocator, 92 PayloadAllocator* allocator,
44 bool* frame_decoded_out) = 0; 93 bool* frame_decoded_out) = 0;
45 94
46 // Creates a Packet from av_frame. 95 // Creates a Packet from av_frame.
47 virtual PacketPtr CreateOutputPacket(const AVFrame& av_frame, 96 virtual PacketPtr CreateOutputPacket(const AVFrame& av_frame,
(...skipping 16 matching lines...) Expand all
64 113
65 AvCodecContextPtr av_codec_context_; 114 AvCodecContextPtr av_codec_context_;
66 AVPacket av_packet_; 115 AVPacket av_packet_;
67 ffmpeg::AvFramePtr av_frame_ptr_; 116 ffmpeg::AvFramePtr av_frame_ptr_;
68 }; 117 };
69 118
70 } // namespace media 119 } // namespace media
71 } // namespace mojo 120 } // namespace mojo
72 121
73 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ 122 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_
OLDNEW
« no previous file with comments | « services/media/framework_ffmpeg/ffmpeg_decoder.cc ('k') | services/media/framework_ffmpeg/ffmpeg_demux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698