[FFmpeg-devel] [PATCH] ffserver: use avcodec_copy_context to copy context

Lukasz Marek lukasz.m.luki2 at gmail.com
Sat Nov 22 02:36:47 CET 2014


Copying context using dedicated function is safer that raw memcpy
which creates shallow copy.

Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
 ffserver.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index e3e76ba..7e36ab1 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3319,13 +3319,8 @@ static AVStream *add_av_stream1(FFServerStream *stream, AVCodecContext *codec, i
     if (!fst)
         return NULL;
     if (copy) {
-        fst->codec = avcodec_alloc_context3(NULL);
-        memcpy(fst->codec, codec, sizeof(AVCodecContext));
-        if (codec->extradata_size) {
-            fst->codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
-            memcpy(fst->codec->extradata, codec->extradata,
-                codec->extradata_size);
-        }
+        fst->codec = avcodec_alloc_context3(codec->codec);
+        avcodec_copy_context(fst->codec, codec);
     } else {
         /* live streams must use the actual feed's codec since it may be
          * updated later to carry extradata needed by them.
-- 
1.9.1



More information about the ffmpeg-devel mailing list