Additional usage of the new api
authorNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 31 Dec 2015 16:37:06 +0000 (11:37 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 31 Dec 2015 16:37:06 +0000 (11:37 -0500)
* src/media/media-ffmpeg.c (media_ffmpeg_open_file): Use
avformat_open_input and avformat_find_stream_info,
avformat_close_input.
(stream_open): Use avformat_open_input.
(media_ffmpeg_close): Use avformat_close_input.
(media_ffmpeg_open): Use avio_size, avformat_find_stream_info,
av_dump_format and avoid warning.
(new_media_ffmpeg_read): Use avformat_close_input.

* src/media/media-ffmpeg.h: Include avcodec.h

* m4/sxe-mm.m4 (SXE_MM_CHECK_FFMPEG): Verify availability of all
the included ffmpeg headers. And additional functions,
avio_alloc_context, avio_size, av_dump_format.
(SXE_CHECK_FFMPEG_HEADERS): Check also for avcodec.h
(SXE_CHECK_FFMPEG_LIBS): Check for av_dump_format,
avio_alloc_context, avio_size.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
m4/sxe-mm.m4
src/media/media-ffmpeg.c
src/media/media-ffmpeg.h

index 67ebc89..0caa1aa 100644 (file)
@@ -332,8 +332,16 @@ AC_DEFUN([SXE_MM_CHECK_FFMPEG], [
        if test "$ac_cv_header_avformat_h" = "yes" -o \
                "$ac_cv_header_ffmpeg_avformat_h" = "yes" -o \
                "$ac_cv_header_libavformat_avformat_h" = "yes"; then
-               sxe_cv_feat_ffmpeg_headers="yes"
+               if test "$ac_cv_header_avcodec_h" = "yes" -o \
+                        "$ac_cv_header_ffmpeg_avcodec_h" = "yes" -o \
+                       "$ac_cv_header_libavcodec_avcodec_h" = "yes"; then
+                       if test "$ac_cv_header_ffmpeg_dict_h" = "yes" -o \
+                               "$ac_cv_header_libavutil_dict_h" = "yes"; then
+                               sxe_cv_feat_ffmpeg_headers="yes"
+                       fi
+               fi
        fi
+
        ## make sure either decode_audio is there
        if test "$ac_cv_lib_avcodec_avcodec_decode_audio4" = "yes"; then
                sxe_cv_feat_ffmpeg_decoders="yes"
@@ -345,13 +353,16 @@ AC_DEFUN([SXE_MM_CHECK_FFMPEG], [
        if test "$sxe_cv_feat_ffmpeg_headers" = "yes" -a \
                "$sxe_cv_feat_ffmpeg_decoders" = "yes" -a \
                "$sxe_cv_feat_ffmpeg_avformat_alloc" = "yes" -a \
+               "$ac_cv_lib_avformat_avio_alloc_context" = "yes" -a \
+               "$ac_cv_lib_avformat_avio_size" = "yes" -a \
+               "$ac_cv_lib_avformat_avformat_open_input" = "yes" -a \
                "$ac_cv_lib_avformat_avformat_close_input" = "yes" -a \
                "$ac_cv_lib_avformat_avformat_find_stream_info" = "yes" -a \
-               "$ac_cv_lib_avformat_avformat_open_input" = "yes" -a \
                "$ac_cv_lib_avformat_av_probe_input_format" = "yes" -a \
                "$ac_cv_lib_avformat_av_read_frame" = "yes" -a \
-               "$ac_cv_lib_avformat_av_register_all" = "yes" -a \
                "$ac_cv_lib_avformat_av_seek_frame" = "yes" -a \
+               "$ac_cv_lib_avformat_av_register_all" = "yes" -a \
+               "$ac_cv_lib_avformat_av_dump_format" = "yes" -a \
                "$ac_cv_lib_avcodec_avcodec_find_decoder" = "yes" -a \
                "$ac_cv_lib_avcodec_avcodec_open2" = "yes" -a \
                "$ac_cv_lib_avutil_av_dict_get" = "yes"; then
@@ -378,6 +389,8 @@ AC_DEFUN([SXE_CHECK_FFMPEG_HEADERS], [dnl
        ## backup current configuration
        SXE_DUMP_LIBS
        CPPFLAGS="${CPPFLAGS} ${FFMPEG_CPPFLAGS}"
+       AC_CHECK_HEADERS([avformat.h avcodec.h])
+       AC_CHECK_HEADERS([ffmpeg/avformat.h ffmpeg/avcodec.h ffmpeg/dict.h])
        AC_CHECK_HEADERS([libavformat/avformat.h libavcodec/avcodec.h libavutil/dict.h])
 
        ## restore configuration
@@ -404,7 +417,10 @@ AC_DEFUN([SXE_CHECK_FFMPEG_LIBS], [dnl
        AC_CHECK_LIB([avformat], [av_read_frame], [:], [:], [${FFMPEG_LIBS}])
        AC_CHECK_LIB([avformat], [av_seek_frame], [:], [:], [${FFMPEG_LIBS}])
        AC_CHECK_LIB([avformat], [av_register_all], [:], [:], [${FFMPEG_LIBS}])
+       AC_CHECK_LIB([avformat], [av_dump_format], [:], [:], [${FFMPEG_LIBS}])
        AC_CHECK_LIB([avformat], [avformat_alloc_context], [:], [:], [${FFMPEG_LIBS}])
+       AC_CHECK_LIB([avformat], [avio_alloc_context], [:], [:], [${FFMPEG_LIBS}])
+       AC_CHECK_LIB([avformat], [avio_size], [:], [:], [${FFMPEG_LIBS}])
 
        AC_CHECK_LIB([avutil], [av_dict_get], [:], [:], [${FFMPEG_LIBS}])
 
index cc5c6b5..3c9693e 100644 (file)
@@ -200,29 +200,18 @@ media_ffmpeg_print(Lisp_Object ms, Lisp_Object pcfun, int ef)
 static AVFormatContext*
 media_ffmpeg_open_file(const char *file)
 {
-#if defined HAVE_AVFORMAT_ALLOC_CONTEXT
-       AVFormatContext *avfc = avformat_alloc_context();
-#elif defined HAVE_AV_ALLOC_FORMAT_CONTEXT
-       /* deprecated already, but `people' like Horst still use this */
-       AVFormatContext *avfc = av_alloc_format_context();
-#else
-# error "Your ffmpeg library is too old.  Adopt a new one."
-#endif /* HAVE_AVFORMAT_ALLOC_CONTEXT */
+       AVFormatContext *avfc = NULL;
 
        /* open the file */
-       if (av_open_input_file(&avfc, file, NULL, 0, NULL) < 0) {
+       if (avformat_open_input(&avfc, file, NULL, NULL) < 0) {
                FFMPEG_DEBUG_AVF("opening file failed.\n");
-               if (avfc)
-                       xfree(avfc);
                return NULL;
        }
 
        /* Retrieve stream information */
-       if (av_find_stream_info(avfc) < 0) {
+       if (avformat_find_stream_info(avfc, NULL) < 0) {
                FFMPEG_DEBUG_AVS("opening stream inside file failed.\n");
-               av_close_input_file(avfc);
-               if (avfc)
-                       xfree(avfc);
+               avformat_close_input(&avfc);
                return NULL;
        }
 
@@ -397,7 +386,7 @@ media_ffmpeg_close(ms_driver_data_t data)
        FFMPEG_DEBUG_AVF("closing AVFormatContext: 0x%lx\n",
                         (long unsigned int)avfc);
        if (avfc && avfc->iformat)
-               av_close_input_file(avfc);
+               avformat_close_input(&avfc);
 }
 
 static void
@@ -541,6 +530,8 @@ media_ffmpeg_open(Lisp_Media_Stream *ms)
                mkfp = media_stream_kind_properties(ms).fprops;
                TO_EXTERNAL_FORMAT(LISP_STRING, mkfp->filename,
                                   ALLOCA, (file, file_len), Qnil);
+               SXE_SET_UNUSED(file_len);
+
                avfc = media_ffmpeg_open_file(file);
                if (!avfc) {
                        media_stream_set_meths(ms, NULL);
@@ -549,7 +540,7 @@ media_ffmpeg_open(Lisp_Media_Stream *ms)
                }
 
                /* store the filesize */
-               mkfp->filesize = avfc->file_size;
+               mkfp->filesize = avio_size(avfc->pb);
                break;
        }
        case MKIND_STRING: {
@@ -1325,7 +1316,7 @@ stream_open(char *filename, size_t filelen)
        ap->time_base= (AVRational){1, 25};
        ap->pix_fmt = PIX_FMT_NONE; /* frame_pix_fmt; */
 
-       err = av_open_input_file(&is->ic, is->filename, is->iformat, 0, ap);
+       err = avformat_open_input(&is->ic, is->filename, is->iformat, NULL /*ap*/);
        if (UNLIKELY(err < 0)) {
                FFMPEG_DEBUG_AVF("Could not open \"%s\" (errno %d)\n",
                                 is->filename, err);
@@ -1381,7 +1372,7 @@ new_media_ffmpeg_open(Lisp_Media_Stream *ms)
        }
 
        if (!use_play) {
-               err = av_find_stream_info(vs->ic);
+               err = avformat_find_stream_info(vs->ic, NULL);
                if (err < 0) {
                        FFMPEG_DEBUG_AVF("\"%s\": "
                                         "could not find codec parameters\n",
@@ -1401,7 +1392,7 @@ new_media_ffmpeg_open(Lisp_Media_Stream *ms)
        av_read_play(vs->ic);
 
        if (use_play) {
-               err = av_find_stream_info(vs->ic);
+               err = avformat_find_stream_info(vs->ic, NULL);
                if (err < 0) {
                        FFMPEG_DEBUG_AVF("\"%s\": "
                                         "could not find codec parameters\n",
@@ -1428,7 +1419,7 @@ new_media_ffmpeg_open(Lisp_Media_Stream *ms)
                }
        }
        if (1 /* show_status */) {
-               dump_format(vs->ic, 0, vs->filename, 0);
+               av_dump_format(vs->ic, 0, vs->filename, 0);
                dump_stream_info(vs->ic);
        }
 
@@ -1607,7 +1598,7 @@ new_media_ffmpeg_read(media_substream *mss, void *outbuf, size_t length)
        if (is->subtitle_stream >= 0)
                stream_component_close(is, is->subtitle_stream);
        if (is->ic) {
-               av_close_input_file(is->ic);
+               avformat_close_input(&is->ic);
                is->ic = NULL; /* safety */
        }
        url_set_interrupt_cb(NULL);
index 66c4541..538a2d6 100644 (file)
@@ -33,6 +33,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 # include <avformat.h>
 #endif
 
+#if defined HAVE_LIBAVCODEC_AVCODEC_H
+# include <libavcodec/avcodec.h>
+#elif defined HAVE_FFMPEG_AVCODEC_H
+# include <ffmpeg/avcodec.h>
+#elif defined HAVE_AVCODEC_H
+# include <avcodec.h>
+#endif
+
 #if defined HAVE_LIBAVUTIL_DICT_H
 # include <libavutil/dict.h>
 #elif defined HAVE_FFMPEG_DICT_H