blob: 6c182d09e2a4e86742aa8a68434e11063ca8193f [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgfdf21c82012-02-02 12:46:58 +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
philipelcce46fc2015-12-21 03:04:49 -080011#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_
12#define WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000014#include <vector>
15
Henrik Kjellander2557b862015-11-18 22:00:21 +010016#include "webrtc/modules/video_coding/include/video_codec_interface.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020017#include "webrtc/rtc_base/checks.h"
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000018#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000022class I420Encoder : public VideoEncoder {
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000023 public:
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000024 I420Encoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000026 virtual ~I420Encoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000027
philipelcce46fc2015-12-21 03:04:49 -080028 // Initialize the encoder with the information from the VideoCodec.
29 //
30 // Input:
31 // - codecSettings : Codec settings.
32 // - numberOfCores : Number of cores available for the encoder.
33 // - maxPayloadSize : The maximum size each payload is allowed
34 // to have. Usually MTU - overhead.
35 //
36 // Return value : WEBRTC_VIDEO_CODEC_OK if OK.
37 // <0 - Error
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 int InitEncode(const VideoCodec* codecSettings,
39 int /*numberOfCores*/,
40 size_t /*maxPayloadSize*/) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
philipelcce46fc2015-12-21 03:04:49 -080042 // "Encode" an I420 image (as a part of a video stream). The encoded image
43 // will be returned to the user via the encode complete callback.
44 //
45 // Input:
46 // - inputImage : Image to be encoded.
47 // - codecSpecificInfo : Pointer to codec specific data.
48 // - frameType : Frame type to be sent (Key /Delta).
49 //
50 // Return value : WEBRTC_VIDEO_CODEC_OK if OK.
51 // <0 - Error
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070052 int Encode(const VideoFrame& inputImage,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000053 const CodecSpecificInfo* /*codecSpecificInfo*/,
pbos22993e12015-10-19 02:39:06 -070054 const std::vector<FrameType>* /*frame_types*/) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
philipelcce46fc2015-12-21 03:04:49 -080056 // Register an encode complete callback object.
57 //
58 // Input:
59 // - callback : Callback object which handles encoded images.
60 //
61 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
philipelcce46fc2015-12-21 03:04:49 -080064 // Free encoder memory.
65 //
66 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000067 int Release() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000069 int SetChannelParameters(uint32_t /*packetLoss*/, int64_t /*rtt*/) override {
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000070 return WEBRTC_VIDEO_CODEC_OK;
71 }
niklase@google.com470e71d2011-07-07 08:21:25 +000072
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000073 private:
philipelcce46fc2015-12-21 03:04:49 -080074 static uint8_t* InsertHeader(uint8_t* buffer,
75 uint16_t width,
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000076 uint16_t height);
77
philipelcce46fc2015-12-21 03:04:49 -080078 bool _inited;
79 EncodedImage _encodedImage;
80 EncodedImageCallback* _encodedCompleteCallback;
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000081}; // class I420Encoder
niklase@google.com470e71d2011-07-07 08:21:25 +000082
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000083class I420Decoder : public VideoDecoder {
pbos@webrtc.org8911ce42013-03-18 16:39:03 +000084 public:
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000085 I420Decoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000086
mikhal@webrtc.orgb95e9ca2012-07-10 20:58:08 +000087 virtual ~I420Decoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000088
philipelcce46fc2015-12-21 03:04:49 -080089 // Initialize the decoder.
90 // The user must notify the codec of width and height values.
91 //
92 // Return value : WEBRTC_VIDEO_CODEC_OK.
93 // <0 - Errors
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000094 int InitDecode(const VideoCodec* codecSettings,
95 int /*numberOfCores*/) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
philipelcce46fc2015-12-21 03:04:49 -080097 // Decode encoded image (as a part of a video stream). The decoded image
98 // will be returned to the user through the decode complete callback.
99 //
100 // Input:
101 // - inputImage : Encoded image to be decoded
102 // - missingFrames : True if one or more frames have been lost
103 // since the previous decode call.
104 // - codecSpecificInfo : pointer to specific codec data
105 // - renderTimeMs : Render time in Ms
106 //
107 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
108 // <0 - Error
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000109 int Decode(const EncodedImage& inputImage,
110 bool missingFrames,
111 const RTPFragmentationHeader* /*fragmentation*/,
112 const CodecSpecificInfo* /*codecSpecificInfo*/,
113 int64_t /*renderTimeMs*/) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
philipelcce46fc2015-12-21 03:04:49 -0800115 // Register a decode complete callback object.
116 //
117 // Input:
118 // - callback : Callback object which handles decoded images.
119 //
120 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000121 int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
philipelcce46fc2015-12-21 03:04:49 -0800123 // Free decoder memory.
124 //
125 // Return value : WEBRTC_VIDEO_CODEC_OK if OK.
126 // <0 - Error
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000127 int Release() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
pbos@webrtc.org8911ce42013-03-18 16:39:03 +0000129 private:
pbos@webrtc.org7f7162a2013-07-30 15:18:31 +0000130 static const uint8_t* ExtractHeader(const uint8_t* buffer,
131 uint16_t* width,
132 uint16_t* height);
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
philipelcce46fc2015-12-21 03:04:49 -0800134 int _width;
135 int _height;
136 bool _inited;
137 DecodedImageCallback* _decodeCompleteCallback;
pbos@webrtc.org8911ce42013-03-18 16:39:03 +0000138}; // class I420Decoder
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
pbos@webrtc.org8911ce42013-03-18 16:39:03 +0000140} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
philipelcce46fc2015-12-21 03:04:49 -0800142#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_