blob: 2c9b0f55b3f4c2170d62f834dceafd3399a6232e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
wu@webrtc.org69f8be32012-02-16 18:32:02 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// This sub-API supports the following functionalities:
12// - Specify render destinations for incoming video streams, capture devices
13// and files.
14// - Configuring render streams.
15
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000016#ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_
17#define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000018
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000019#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
niklase@google.com470e71d2011-07-07 08:21:25 +000023class VideoEngine;
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000024class VideoRender;
pbos@webrtc.orgd29d4e92013-11-20 13:19:54 +000025class VideoRenderCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// This class declares an abstract interface to be used for external renderers.
28// The user implemented derived class is registered using AddRenderer().
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000029class ExternalRenderer {
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000030 public:
31 // This method will be called when the stream to be rendered changes in
32 // resolution or number of streams mixed in the image.
33 virtual int FrameSizeChange(unsigned int width,
34 unsigned int height,
35 unsigned int number_of_streams) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000037 // This method is called when a new frame should be rendered.
38 virtual int DeliverFrame(unsigned char* buffer,
39 int buffer_size,
wu@webrtc.org69f8be32012-02-16 18:32:02 +000040 // RTP timestamp in 90kHz.
wu@webrtc.org6c75c982014-04-15 17:46:33 +000041 uint32_t timestamp,
42 // NTP time of the capture time in local timebase
43 // in milliseconds.
44 int64_t ntp_time_ms,
45 // Wallclock render time in milliseconds.
46 int64_t render_time_ms,
47 // Handle of the underlying video frame.
wu@webrtc.org9dba5252013-08-05 20:36:57 +000048 void* handle) = 0;
49
50 // Returns true if the renderer supports textures. DeliverFrame can be called
51 // with NULL |buffer| and non-NULL |handle|.
52 virtual bool IsTextureSupported() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000054 protected:
55 virtual ~ExternalRenderer() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000056};
57
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000058class ViERender {
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000059 public:
60 // Factory for the ViERender sub‐API and increases an internal reference
61 // counter if successful. Returns NULL if the API is not supported or if
62 // construction fails.
63 static ViERender* GetInterface(VideoEngine* video_engine);
niklase@google.com470e71d2011-07-07 08:21:25 +000064
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000065 // Releases the ViERender sub-API and decreases an internal reference
66 // counter. Returns the new reference count. This value should be zero
67 // for all sub-API:s before the VideoEngine object can be safely deleted.
68 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000070 // Registers render module.
71 virtual int RegisterVideoRenderModule(VideoRender& render_module) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000073 // Deregisters render module.
74 virtual int DeRegisterVideoRenderModule(VideoRender& render_module) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000076 // Sets the render destination for a given render ID.
77 virtual int AddRenderer(const int render_id,
78 void* window,
79 const unsigned int z_order,
80 const float left,
81 const float top,
82 const float right,
83 const float bottom) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000085 // Removes the renderer for a stream.
86 virtual int RemoveRenderer(const int render_id) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000088 // Starts rendering a render stream.
89 virtual int StartRender(const int render_id) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000091 // Stops rendering a render stream.
92 virtual int StopRender(const int render_id) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000093
mflodman@webrtc.orgf4f21452012-09-28 11:27:35 +000094 // Set expected render time needed by graphics card or external renderer, i.e.
95 // the number of ms a frame will be sent to rendering before the actual render
96 // time.
97 virtual int SetExpectedRenderDelay(int render_id, int render_delay) = 0;
98
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000099 // Configures an already added render stream.
100 virtual int ConfigureRender(int render_id,
101 const unsigned int z_order,
102 const float left,
103 const float top,
104 const float right,
105 const float bottom) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000107 // This function mirrors the rendered stream left and right or up and down.
108 virtual int MirrorRenderStream(const int render_id,
109 const bool enable,
110 const bool mirror_xaxis,
111 const bool mirror_yaxis) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000113 // External render.
114 virtual int AddRenderer(const int render_id,
115 RawVideoType video_input_format,
116 ExternalRenderer* renderer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.orgd29d4e92013-11-20 13:19:54 +0000118 // Propagating VideoRenderCallback down to the VideoRender module for new API.
119 // Contains default-implementation not to break code mocking this interface.
120 // (Ugly, but temporary.)
121 virtual int AddRenderCallback(int render_id, VideoRenderCallback* callback) {
122 return 0;
123 }
124
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000125 protected:
126 ViERender() {}
127 virtual ~ViERender() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000128};
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000129
130} // namespace webrtc
131
132#endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_