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

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

Issue 2077413003: Motown: Various fixes related to video playback support (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Comments and name changes for clarity. Created 4 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
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. 38 class DecoderPacket : public Packet {
39 class AvBufferContext {
40 public: 39 public:
41 AvBufferContext(size_t size, PayloadAllocator* allocator) 40 static PacketPtr Create(int64_t pts, AVBufferRef* av_buffer_ref) {
42 : size_(size), allocator_(allocator) { 41 return PacketPtr(new DecoderPacket(pts, av_buffer_ref));
43 DCHECK(allocator_);
44 if (size_ == 0) {
45 buffer_ = nullptr;
46 } else {
47 buffer_ =
48 static_cast<uint8_t*>(allocator_->AllocatePayloadBuffer(size_));
49 }
50 } 42 }
51 43
52 ~AvBufferContext() { 44 protected:
53 if (allocator_ == nullptr) { 45 ~DecoderPacket() override;
54 // Previously released.
55 return;
56 }
57 46
58 if (size_ != 0) { 47 void Release() override;
59 DCHECK(buffer_ != nullptr);
60 allocator_->ReleasePayloadBuffer(buffer_);
61 return;
62 }
63 48
64 DCHECK(buffer_ == nullptr); 49 private:
50 DecoderPacket(int64_t pts, AVBufferRef* av_buffer_ref)
51 : Packet(pts,
52 false,
53 static_cast<size_t>(av_buffer_ref->size),
54 av_buffer_ref->data),
55 av_buffer_ref_(av_buffer_ref) {
56 DCHECK(av_buffer_ref->size >= 0);
65 } 57 }
66 58
67 uint8_t* buffer() { return buffer_; } 59 AVBufferRef* av_buffer_ref_;
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 }; 60 };
86 61
87 // Decodes from av_packet into av_frame_ptr. The result indicates how many 62 // Decodes from av_packet into av_frame_ptr. The result indicates how many
88 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether 63 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether
89 // av_frame_ptr contains a complete frame. 64 // av_frame_ptr contains a complete frame.
90 virtual int Decode(const AVPacket& av_packet, 65 virtual int Decode(const AVPacket& av_packet,
91 const ffmpeg::AvFramePtr& av_frame_ptr, 66 const ffmpeg::AvFramePtr& av_frame_ptr,
92 PayloadAllocator* allocator, 67 PayloadAllocator* allocator,
93 bool* frame_decoded_out) = 0; 68 bool* frame_decoded_out) = 0;
94 69
(...skipping 18 matching lines...) Expand all
113 88
114 AvCodecContextPtr av_codec_context_; 89 AvCodecContextPtr av_codec_context_;
115 AVPacket av_packet_; 90 AVPacket av_packet_;
116 ffmpeg::AvFramePtr av_frame_ptr_; 91 ffmpeg::AvFramePtr av_frame_ptr_;
117 }; 92 };
118 93
119 } // namespace media 94 } // namespace media
120 } // namespace mojo 95 } // namespace mojo
121 96
122 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ 97 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_
OLDNEW
« no previous file with comments | « services/media/framework_ffmpeg/ffmpeg_audio_decoder.cc ('k') | services/media/framework_ffmpeg/ffmpeg_decoder_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698