| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 #ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <list> | |
| 12 #include <queue> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/macros.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/threading/thread_checker.h" | |
| 18 #include "base/timer/timer.h" | |
| 19 #include "base/tuple.h" | |
| 20 #include "content/common/content_export.h" | |
| 21 #include "media/base/android/sdk_media_codec_bridge.h" | |
| 22 #include "media/video/video_encode_accelerator.h" | |
| 23 | |
| 24 namespace media { | |
| 25 class BitstreamBuffer; | |
| 26 } // namespace media | |
| 27 | |
| 28 namespace content { | |
| 29 | |
| 30 // Android-specific implementation of media::VideoEncodeAccelerator, enabling | |
| 31 // hardware-acceleration of video encoding, based on Android's MediaCodec class | |
| 32 // (http://developer.android.com/reference/android/media/MediaCodec.html). This | |
| 33 // class expects to live and be called on a single thread (the GPU process' | |
| 34 // ChildThread). | |
| 35 class CONTENT_EXPORT AndroidVideoEncodeAccelerator | |
| 36 : public media::VideoEncodeAccelerator { | |
| 37 public: | |
| 38 AndroidVideoEncodeAccelerator(); | |
| 39 ~AndroidVideoEncodeAccelerator() override; | |
| 40 | |
| 41 // media::VideoEncodeAccelerator implementation. | |
| 42 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() | |
| 43 override; | |
| 44 bool Initialize(media::VideoPixelFormat format, | |
| 45 const gfx::Size& input_visible_size, | |
| 46 media::VideoCodecProfile output_profile, | |
| 47 uint32_t initial_bitrate, | |
| 48 Client* client) override; | |
| 49 void Encode(const scoped_refptr<media::VideoFrame>& frame, | |
| 50 bool force_keyframe) override; | |
| 51 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | |
| 52 void RequestEncodingParametersChange(uint32_t bitrate, | |
| 53 uint32_t framerate) override; | |
| 54 void Destroy() override; | |
| 55 | |
| 56 private: | |
| 57 enum { | |
| 58 // Arbitrary choice. | |
| 59 INITIAL_FRAMERATE = 30, | |
| 60 // Until there are non-realtime users, no need for unrequested I-frames. | |
| 61 IFRAME_INTERVAL = INT32_MAX, | |
| 62 }; | |
| 63 | |
| 64 // Impedance-mismatch fixers: MediaCodec is a poll-based API but VEA is a | |
| 65 // push-based API; these methods turn the crank to make the two work together. | |
| 66 void DoIOTask(); | |
| 67 void QueueInput(); | |
| 68 void DequeueOutput(); | |
| 69 | |
| 70 // Start & stop |io_timer_| if the time seems right. | |
| 71 void MaybeStartIOTimer(); | |
| 72 void MaybeStopIOTimer(); | |
| 73 | |
| 74 // Used to DCHECK that we are called on the correct thread. | |
| 75 base::ThreadChecker thread_checker_; | |
| 76 | |
| 77 // VideoDecodeAccelerator::Client callbacks go here. Invalidated once any | |
| 78 // error triggers. | |
| 79 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | |
| 80 | |
| 81 std::unique_ptr<media::VideoCodecBridge> media_codec_; | |
| 82 | |
| 83 // Bitstream buffers waiting to be populated & returned to the client. | |
| 84 std::vector<media::BitstreamBuffer> available_bitstream_buffers_; | |
| 85 | |
| 86 // Frames waiting to be passed to the codec, queued until an input buffer is | |
| 87 // available. Each element is a tuple of <Frame, key_frame, enqueue_time>. | |
| 88 typedef std::queue< | |
| 89 base::Tuple<scoped_refptr<media::VideoFrame>, bool, base::Time>> | |
| 90 PendingFrames; | |
| 91 PendingFrames pending_frames_; | |
| 92 | |
| 93 // Repeating timer responsible for draining pending IO to the codec. | |
| 94 base::RepeatingTimer io_timer_; | |
| 95 | |
| 96 // The difference between number of buffers queued & dequeued at the codec. | |
| 97 int32_t num_buffers_at_codec_; | |
| 98 | |
| 99 // A monotonically-growing value, used as a fake timestamp just to keep things | |
| 100 // appearing to move forward. | |
| 101 base::TimeDelta fake_input_timestamp_; | |
| 102 | |
| 103 // Resolution of input stream. Set once in initialization and not allowed to | |
| 104 // change after. | |
| 105 gfx::Size frame_size_; | |
| 106 | |
| 107 uint32_t last_set_bitrate_; // In bps. | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(AndroidVideoEncodeAccelerator); | |
| 110 }; | |
| 111 | |
| 112 } // namespace content | |
| 113 | |
| 114 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ | |
| OLD | NEW |