From d891ac338115e8615a635c179ac7bd245b127876 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Thu, 16 Nov 2017 19:09:16 +0100 Subject: [PATCH] check alloc AVFormatContext Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/fd512df7cbd3f2d72ee63bd9b327ff04a24bde8d Author: Jacek Jendrzej Date: 2017-11-16 (Thu, 16 Nov 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libarmbox/video.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libarmbox/video.cpp b/libarmbox/video.cpp index 3eaac62..19b41b3 100644 --- a/libarmbox/video.cpp +++ b/libarmbox/video.cpp @@ -225,14 +225,10 @@ AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext } AVCodecContext * codecContext = formatContext->streams[stream_index]->codec; AVCodec *codec = avcodec_find_decoder(codecContext->codec_id); - if (!codec){ + if (codec && (avcodec_open2(codecContext, codec, NULL)) != 0){ return NULL; } - if ((avcodec_open2(codecContext, codec, NULL)) != 0){ - return NULL; - } - - return codecContext; + return codecContext; } int image_to_mpeg2(const char *image_name, const char *encode_name) @@ -242,7 +238,7 @@ int image_to_mpeg2(const char *image_name, const char *encode_name) avcodec_register_all(); AVFormatContext *formatContext = avformat_alloc_context(); - if ((ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0){ + if (formatContext && (ret = avformat_open_input(&formatContext, path, NULL, NULL)) == 0){ AVCodecContext *codecContext = open_codec(AVMEDIA_TYPE_VIDEO, formatContext); if(codecContext){ AVPacket packet;