OLD | NEW |
(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 #ifndef EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ |
| 6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/stl_util.h" |
| 12 #include "media/base/video_frame.h" |
| 13 #include "media/video/video_encode_accelerator.h" |
| 14 #include "third_party/wds/src/libwds/public/video_format.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 // This structure represents an encoded video frame. |
| 19 struct WiFiDisplayEncodedFrame { |
| 20 const uint8_t* bytes() const { |
| 21 return reinterpret_cast<uint8_t*>( |
| 22 string_as_array(const_cast<std::string*>(&data))); |
| 23 } |
| 24 uint8_t* mutable_bytes() { |
| 25 return reinterpret_cast<uint8_t*>(string_as_array(&data)); |
| 26 } |
| 27 |
| 28 base::TimeTicks pts; // Presentation timestamp. |
| 29 base::TimeTicks dts; // Decoder timestamp. |
| 30 std::string data; |
| 31 bool key_frame; |
| 32 }; |
| 33 |
| 34 // This interface represents H.264 video encoder used by the |
| 35 // Wi-Fi Display media pipeline. |
| 36 // Threading: the client code should belong to a single thread. |
| 37 class WiFiDisplayVideoEncoder : |
| 38 public base::RefCountedThreadSafe<WiFiDisplayVideoEncoder> { |
| 39 public: |
| 40 using EncodedFrameCallback = |
| 41 base::Callback<void(const WiFiDisplayEncodedFrame&)>; |
| 42 |
| 43 using VideoEncoderCallback = |
| 44 base::Callback<void(scoped_refptr<WiFiDisplayVideoEncoder>)>; |
| 45 |
| 46 using ReceiveVideoEncodeAcceleratorCallback = |
| 47 base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>, |
| 48 std::unique_ptr<media::VideoEncodeAccelerator>)>; |
| 49 using CreateVideoEncodeAcceleratorCallback = |
| 50 base::Callback<void(const ReceiveVideoEncodeAcceleratorCallback&)>; |
| 51 |
| 52 using ReceiveEncodeMemoryCallback = |
| 53 base::Callback<void(std::unique_ptr<base::SharedMemory>)>; |
| 54 using CreateEncodeMemoryCallback = |
| 55 base::Callback<void(size_t size, const ReceiveEncodeMemoryCallback&)>; |
| 56 |
| 57 struct InitParameters { |
| 58 InitParameters(); |
| 59 ~InitParameters(); |
| 60 gfx::Size frame_size; |
| 61 int frame_rate; |
| 62 int bit_rate; |
| 63 wds::H264Profile profile; |
| 64 wds::H264Level level; |
| 65 // VEA-specific parameters. |
| 66 CreateEncodeMemoryCallback create_memory_callback; |
| 67 CreateVideoEncodeAcceleratorCallback vea_create_callback; |
| 68 }; |
| 69 |
| 70 // A factory method that creates a new encoder instance from the given |
| 71 // |params|, the encoder instance is returned as an argument of |
| 72 // |result_callback| ('nullptr' argument means encoder creation failure). |
| 73 static void Create( |
| 74 const InitParameters& params, |
| 75 const VideoEncoderCallback& encoder_callback); |
| 76 |
| 77 // Encodes the given raw frame. The resulting encoded frame is passed |
| 78 // as an |encoded_callback|'s argument which is set via 'SetCallbacks' |
| 79 // method. |
| 80 virtual void InsertRawVideoFrame( |
| 81 const scoped_refptr<media::VideoFrame>& video_frame, |
| 82 base::TimeTicks reference_time) = 0; |
| 83 |
| 84 // Requests the next encoded frame to be an instantaneous decoding refresh |
| 85 // (IDR) picture. |
| 86 virtual void RequestIDRPicture() = 0; |
| 87 |
| 88 // Sets callbacks for the obtained encoder instance: |
| 89 // |encoded_callback| is invoked to return the next encoded frame |
| 90 // |error_callback| is invoked to report a fatal encoder error |
| 91 void SetCallbacks(const EncodedFrameCallback& encoded_callback, |
| 92 const base::Closure& error_callback); |
| 93 |
| 94 protected: |
| 95 friend class base::RefCountedThreadSafe<WiFiDisplayVideoEncoder>; |
| 96 WiFiDisplayVideoEncoder(); |
| 97 virtual ~WiFiDisplayVideoEncoder(); |
| 98 |
| 99 EncodedFrameCallback encoded_callback_; |
| 100 base::Closure error_callback_; |
| 101 }; |
| 102 |
| 103 } // namespace extensions |
| 104 |
| 105 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDE
O_ENCODER_H_ |
OLD | NEW |