History

libavdevice/decklink: add support for 10-bit output for Decklink SDI

Can be tested via the following command: ./ffmpeg -i foo.ts -f decklink -vcodec v210 'DeckLink Duo (1)' Note that the 8-bit support works as it did before, and setting the pix_fmt isn't required for 10-bit mode. The code defaults to operating in 8-bit mode when no vcodec is specified, for backward compatibility. Updated to reflect feedback from Marton Balint <cus@passwd.hu>

Devin Heitmueller committed 9 years ago

Commit 77f7d711 parent 278588c1 file · +83 −29Browse files

Showing the changes to libavdevice/decklink_enc.cpp (1 of 1 file). Show all

Unified · Split

libavdevice/decklink_enc.cpp+83−29
@@ -44,20 +44,45 @@ extern "C" { · 43 unmodified lines
4444 class decklink_frame : public IDeckLinkVideoFrame
4545 {
4646 public:
47− decklink_frame(struct decklink_ctx *ctx, AVFrame *avframe) :
48− _ctx(ctx), _avframe(avframe), _refs(1) { }
49−
50− virtual long STDMETHODCALLTYPE GetWidth (void) { return _avframe->width; }
51− virtual long STDMETHODCALLTYPE GetHeight (void) { return _avframe->height; }
52− virtual long STDMETHODCALLTYPE GetRowBytes (void) { return _avframe->linesize[0] < 0 ? -_avframe->linesize[0] : _avframe->linesize[0]; }
53− virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void) { return bmdFormat8BitYUV; }
54− virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags (void) { return _avframe->linesize[0] < 0 ? bmdFrameFlagFlipVertical : bmdFrameFlagDefault; }
55− virtual HRESULT STDMETHODCALLTYPE GetBytes (void **buffer)
47+ decklink_frame(struct decklink_ctx *ctx, AVFrame *avframe, AVCodecID codec_id, int height, int width) :
48+ _ctx(ctx), _avframe(avframe), _avpacket(NULL), _codec_id(codec_id), _height(height), _width(width), _refs(1) { }
49+ decklink_frame(struct decklink_ctx *ctx, AVPacket *avpacket, AVCodecID codec_id, int height, int width) :
50+ _ctx(ctx), _avframe(NULL), _avpacket(avpacket), _codec_id(codec_id), _height(height), _width(width), _refs(1) { }
51+
52+ virtual long STDMETHODCALLTYPE GetWidth (void) { return _width; }
53+ virtual long STDMETHODCALLTYPE GetHeight (void) { return _height; }
54+ virtual long STDMETHODCALLTYPE GetRowBytes (void)
55+ {
56+ if (_codec_id == AV_CODEC_ID_WRAPPED_AVFRAME)
57+ return _avframe->linesize[0] < 0 ? -_avframe->linesize[0] : _avframe->linesize[0];
58+ else
59+ return ((GetWidth() + 47) / 48) * 128;
60+ }
61+ virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void)
5662 {
57− if (_avframe->linesize[0] < 0)
58− *buffer = (void *)(_avframe->data[0] + _avframe->linesize[0] * (_avframe->height - 1));
63+ if (_codec_id == AV_CODEC_ID_WRAPPED_AVFRAME)
64+ return bmdFormat8BitYUV;
5965 else
60− *buffer = (void *)(_avframe->data[0]);
66+ return bmdFormat10BitYUV;
67+ }
68+ virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags (void)
69+ {
70+ if (_codec_id == AV_CODEC_ID_WRAPPED_AVFRAME)
71+ return _avframe->linesize[0] < 0 ? bmdFrameFlagFlipVertical : bmdFrameFlagDefault;
72+ else
73+ return bmdFrameFlagDefault;
74+ }
75+
76+ virtual HRESULT STDMETHODCALLTYPE GetBytes (void **buffer)
77+ {
78+ if (_codec_id == AV_CODEC_ID_WRAPPED_AVFRAME) {
79+ if (_avframe->linesize[0] < 0)
80+ *buffer = (void *)(_avframe->data[0] + _avframe->linesize[0] * (_avframe->height - 1));
81+ else
82+ *buffer = (void *)(_avframe->data[0]);
83+ } else {
84+ *buffer = (void *)(_avpacket->data);
85+ }
6186 return S_OK;
6287 }
6388
@@ -71,6 +96,7 @@ public: · 7 unmodified lines
7196 int ret = --_refs;
7297 if (!ret) {
7398 av_frame_free(&_avframe);
99+ av_packet_free(&_avpacket);
74100 delete this;
75101 }
76102 return ret;
@@ -78,6 +104,10 @@ public: · 1 unmodified line
78104
79105 struct decklink_ctx *_ctx;
80106 AVFrame *_avframe;
107+ AVPacket *_avpacket;
108+ AVCodecID _codec_id;
109+ int _height;
110+ int _width;
81111
82112 private:
83113 std::atomic<int> _refs;
@@ -90,9 +120,11 @@ public: · 6 unmodified lines
90120 {
91121 decklink_frame *frame = static_cast<decklink_frame *>(_frame);
92122 struct decklink_ctx *ctx = frame->_ctx;
93− AVFrame *avframe = frame->_avframe;
94123
95− av_frame_unref(avframe);
124+ if (frame->_avframe)
125+ av_frame_unref(frame->_avframe);
126+ if (frame->_avpacket)
127+ av_packet_unref(frame->_avpacket);
96128
97129 pthread_mutex_lock(&ctx->mutex);
98130 ctx->frames_buffer_available_spots++;
@@ -118,11 +150,18 @@ static int decklink_setup_video(AVFormatContext *avctx, AVStream *st) · 19 unmodified lines
118150 return -1;
119151 }
120152
121− if (c->format != AV_PIX_FMT_UYVY422) {
122− av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format!"
123− " Only AV_PIX_FMT_UYVY422 is supported.\n");
153+ if (c->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME) {
154+ if (c->format != AV_PIX_FMT_UYVY422) {
155+ av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format!"
156+ " Only AV_PIX_FMT_UYVY422 is supported.\n");
157+ return -1;
158+ }
159+ } else if (c->codec_id != AV_CODEC_ID_V210) {
160+ av_log(avctx, AV_LOG_ERROR, "Unsupported codec type!"
161+ " Only V210 and wrapped frame with AV_PIX_FMT_UYVY422 are supported.\n");
124162 return -1;
125163 }
164+
126165 if (ff_decklink_set_format(avctx, c->width, c->height,
127166 st->time_base.num, st->time_base.den, c->field_order)) {
128167 av_log(avctx, AV_LOG_ERROR, "Unsupported video size, framerate or field order!"
@@ -230,27 +269,42 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt) · 101 unmodified lines
230269 {
231270 struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
232271 struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
233− AVFrame *avframe, *tmp = (AVFrame *)pkt->data;
272+ AVStream *st = avctx->streams[pkt->stream_index];
273+ AVFrame *avframe = NULL, *tmp = (AVFrame *)pkt->data;
274+ AVPacket *avpacket = NULL;
234275 decklink_frame *frame;
235276 buffercount_type buffered;
236277 HRESULT hr;
237278
238− if (tmp->format != AV_PIX_FMT_UYVY422 ||
239− tmp->width != ctx->bmd_width ||
240− tmp->height != ctx->bmd_height) {
241− av_log(avctx, AV_LOG_ERROR, "Got a frame with invalid pixel format or dimension.\n");
242− return AVERROR(EINVAL);
243− }
244− avframe = av_frame_clone(tmp);
245− if (!avframe) {
246− av_log(avctx, AV_LOG_ERROR, "Could not clone video frame.\n");
247− return AVERROR(EIO);
279+ if (st->codecpar->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME) {
280+ if (tmp->format != AV_PIX_FMT_UYVY422 ||
281+ tmp->width != ctx->bmd_width ||
282+ tmp->height != ctx->bmd_height) {
283+ av_log(avctx, AV_LOG_ERROR, "Got a frame with invalid pixel format or dimension.\n");
284+ return AVERROR(EINVAL);
285+ }
286+
287+ avframe = av_frame_clone(tmp);
288+ if (!avframe) {
289+ av_log(avctx, AV_LOG_ERROR, "Could not clone video frame.\n");
290+ return AVERROR(EIO);
291+ }
292+
293+ frame = new decklink_frame(ctx, avframe, st->codecpar->codec_id, avframe->height, avframe->width);
294+ } else {
295+ avpacket = av_packet_clone(pkt);
296+ if (!avpacket) {
297+ av_log(avctx, AV_LOG_ERROR, "Could not clone video frame.\n");
298+ return AVERROR(EIO);
299+ }
300+
301+ frame = new decklink_frame(ctx, avpacket, st->codecpar->codec_id, ctx->bmd_height, ctx->bmd_width);
248302 }
249303
250− frame = new decklink_frame(ctx, avframe);
251304 if (!frame) {
252305 av_log(avctx, AV_LOG_ERROR, "Could not create new frame.\n");
253306 av_frame_free(&avframe);
307+ av_packet_free(&avpacket);
254308 return AVERROR(EIO);
255309 }
256310

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t