More update to newer ffmpeg API
authorNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 31 Dec 2015 19:15:14 +0000 (14:15 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 31 Dec 2015 19:15:14 +0000 (14:15 -0500)
* src/media/media-ffmpeg.h: Add include of avutil/time.h

* src/media/media-ffmpeg.c (AVCODEC_MAX_AUDIO_FRAME_SIZE): Add
define if missing to last known legacy value.
(media_ffmpeg_open): Properly use avcodec_open2
(media_ffmpeg_read): Fix warnings.

* m4/sxe-mm.m4 (SXE_CHECK_FFMPEG_HEADERS): Check also avutil/time.h.
(SXE_CHECK_FFMPEG_LIBS): Check for avformat_free_context and avio_feof.
(SXE_MM_CHECK_FFMPEG): Refactor header check for ease of adding
additional ones.  Verify avformat_free_context and avio_feof are
available.

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

index 0caa1aa..ef8d3a8 100644 (file)
@@ -332,29 +332,51 @@ 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
-               if test "$ac_cv_header_avcodec_h" = "yes" -o \
+               sxe_cv_feat_ffmpeg_headers="yes"
+       else
+               sxe_cv_feat_ffmpeg_headers="no"
+       fi
+
+       if test "$sxe_cv_feat_ffmpeg_headers" = "yes"; then
+               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
+                       sxe_cv_feat_ffmpeg_headers="yes"
+               else
+                       sxe_cv_feat_ffmpeg_headers="no"
                fi
        fi
 
-       ## make sure either decode_audio is there
+       if test "$sxe_cv_feat_ffmpeg_headers" = "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"
+               else
+                       sxe_cv_feat_ffmpeg_headers="no"
+               fi
+       fi
+
+       if test "$sxe_cv_feat_ffmpeg_headers" = "yes"; then
+               if test "$ac_cv_header_ffmpeg_time_h" = "yes" -o \
+                       "$ac_cv_header_libavutil_time_h" = "yes"; then
+                       sxe_cv_feat_ffmpeg_headers="yes"
+               else
+                       sxe_cv_feat_ffmpeg_headers="no"
+               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"
        fi
-       ## make sure this bloody av context allocator is there
-       if test "$ac_cv_lib_avformat_avformat_alloc_context" = "yes"; then
-               sxe_cv_feat_ffmpeg_avformat_alloc="yes"
-       fi
+
        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_avformat_alloc_context" = "yes" -a \
+               "$ac_cv_lib_avformat_avformat_free_context" = "yes" -a \
                "$ac_cv_lib_avformat_avio_alloc_context" = "yes" -a \
                "$ac_cv_lib_avformat_avio_size" = "yes" -a \
+               "$ac_cv_lib_avformat_avio_feof" = "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 \
@@ -390,8 +412,10 @@ AC_DEFUN([SXE_CHECK_FFMPEG_HEADERS], [dnl
        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])
+       AC_CHECK_HEADERS([ffmpeg/avformat.h ffmpeg/avcodec.h])
+       AC_CHECK_HEADERS([ffmpeg/dict.h ffmpeg/time.h])
+       AC_CHECK_HEADERS([libavformat/avformat.h libavcodec/avcodec.h])
+       AC_CHECK_HEADERS([libavutil/dict.h libavutil/time.h])
 
        ## restore configuration
        SXE_RESTORE_LIBS
@@ -419,8 +443,10 @@ AC_DEFUN([SXE_CHECK_FFMPEG_LIBS], [dnl
        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], [avformat_free_context], [:], [:], [${FFMPEG_LIBS}])
        AC_CHECK_LIB([avformat], [avio_alloc_context], [:], [:], [${FFMPEG_LIBS}])
        AC_CHECK_LIB([avformat], [avio_size], [:], [:], [${FFMPEG_LIBS}])
+       AC_CHECK_LIB([avformat], [avio_feof], [:], [:], [${FFMPEG_LIBS}])
 
        AC_CHECK_LIB([avutil], [av_dict_get], [:], [:], [${FFMPEG_LIBS}])
 
index 244cdb8..d7fa9f9 100644 (file)
@@ -87,6 +87,10 @@ DEFINE_MEDIA_DRIVER_CUSTOM(new_media_ffmpeg,
                           new_media_ffmpeg_rewind, NULL);
 
 \f
+#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 19200
+#endif
+
 static int
 media_ffmpeg_bitrate(AVCodecContext *enc)
 {
@@ -529,7 +533,7 @@ media_ffmpeg_open(Lisp_Media_Stream *ms)
                            avcc->codec_id != CODEC_ID_NONE &&
                            avcc->codec_type != AVMEDIA_TYPE_DATA &&
                            (avc = avcodec_find_decoder(avcc->codec_id)) &&
-                           (avc && (avcodec_open(avcc, avc) >= 0))) {
+                           (avc && (avcodec_open2(avcc, avc, NULL) >= 0))) {
 
                                /* create a substream */
                                mss = make_media_substream_append(ms);
@@ -611,7 +615,7 @@ media_ffmpeg_read(media_substream *mss, void *outbuf, size_t length)
        AVFormatContext *avfc;
        AVStream *avst;
        AVCodecContext *avcc;
-       AVCodec *avc;
+       const AVCodec *avc;
        AVPacket pkt;
        /* buffering */
        /* the size we present here, is _not_ the size we want, however
@@ -637,6 +641,7 @@ media_ffmpeg_read(media_substream *mss, void *outbuf, size_t length)
        avst = avfc->streams[si];
        avcc = avst->codec;
        avc = avcc->codec;
+       SXE_SET_UNUSED(avc);
 
        /* unpack the substream */
        if ((mtap = media_substream_type_properties(mss).aprops) == NULL) {
@@ -695,6 +700,8 @@ media_ffmpeg_read(media_substream *mss, void *outbuf, size_t length)
                                         (long long int)pkt.pts,
                                         (long long int)pkt.dts,
                                         pkt.size, size, declen);
+                       /* Because FFMPEG_DEBUG_AVF may expand to nothing ... */
+                       SXE_SET_UNUSED(declen);
 
                        /* memcpy(outbuf+bufseek, (char*)buffer, size); */
                        bufseek += size;
index 538a2d6..6393772 100644 (file)
@@ -47,6 +47,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 # include <ffmpeg/dict.h>
 #endif
 
+#if defined HAVE_LIBAVUTIL_TIME_H
+# include <libavutil/time.h>
+#elif defined HAVE_FFMPEG_TIME_H
+# include <ffmpeg/time.h>
+#endif
+
 /* Newer ffmpeg do not declare this macro... */
 #ifndef DECLARE_ALIGNED
 #ifdef __ICC