From c8f147cff360a4b187e2cf7ef1d848e162a156a8 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Sun, 14 Aug 2016 22:48:35 +0200
Subject: [PATCH] avcodec: wrapped avframe for audio

---
 libavcodec/utils.c    | 5 +++--
 libavformat/nullenc.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 783f62c..8280dd8 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1337,7 +1337,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         avctx->codec_id   = codec->id;
     }
     if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
-                                         && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
+                                         && (avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT) &&
+                                            (avctx->codec_id != AV_CODEC_ID_WRAPPED_AVFRAME))) {
         av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
         ret = AVERROR(EINVAL);
         goto free_and_end;
@@ -1824,7 +1825,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
     }
 
     /* check for valid frame size */
-    if (frame) {
+    if (frame && avctx->codec->id != AV_CODEC_ID_WRAPPED_AVFRAME) {
         if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
             if (frame->nb_samples > avctx->frame_size) {
                 av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
diff --git a/libavformat/nullenc.c b/libavformat/nullenc.c
index fd293d7..3f08615 100644
--- a/libavformat/nullenc.c
+++ b/libavformat/nullenc.c
@@ -29,7 +29,7 @@ static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 AVOutputFormat ff_null_muxer = {
     .name              = "null",
     .long_name         = NULL_IF_CONFIG_SMALL("raw null video"),
-    .audio_codec       = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
+    .audio_codec       = AV_CODEC_ID_WRAPPED_AVFRAME,
     .video_codec       = AV_CODEC_ID_WRAPPED_AVFRAME,
     .write_packet      = null_write_packet,
     .flags             = AVFMT_VARIABLE_FPS | AVFMT_NOFILE | AVFMT_NOTIMESTAMPS,
-- 
2.8.3

