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