replace 'av_init_packet' to 'av_packet_alloc' 83/267783/5 accepted/tizen/unified/20211213.133601 submit/tizen/20211209.083747
authorJiyong Min <jiyong.min@samsung.com>
Fri, 10 Dec 2021 00:17:07 +0000 (09:17 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Fri, 10 Dec 2021 03:32:56 +0000 (12:32 +0900)
 - 'av_init_packet' function was deplicated since ffmpeg 4.4.1

Change-Id: If7a7aa1329b0ed95172eeb5fe080ed73e665b544

formats/ffmpeg/mm_file_format_ffmpeg.c
formats/ffmpeg/mm_file_format_frame.c
packaging/libmm-fileinfo.spec

index 7bb1ea6..0ba3a7d 100644 (file)
@@ -1054,7 +1054,7 @@ static int _get_first_good_video_frame(AVFormatContext *pFormatCtx, AVCodecConte
 #define        _FRAME_SEARCH_LIMIT_CDIS                10
 
        /* AVStream *st = NULL; */
-       AVPacket pkt;
+       AVPacket *pkt = NULL;
 
        AVFrame *frame = NULL;
        AVFrame *tmp_frame = NULL;
@@ -1091,25 +1091,29 @@ static int _get_first_good_video_frame(AVFormatContext *pFormatCtx, AVCodecConte
        pCodecCtx->skip_frame = AVDISCARD_BIDIR;
 
        for (i = 0, v = 0, key_detected = 0, frame = first_frame; i < key_search_limit && v < frame_search_limit;) {
-               av_init_packet(&pkt);
+               pkt = av_packet_alloc();
+               if (!pkt) {
+                       debug_error(DEBUG, "packet allocation failed.");
+                       break;
+               }
 
-               ret = av_read_frame(pFormatCtx, &pkt);
+               ret = av_read_frame(pFormatCtx, pkt);
                if (ret < 0) {
                        debug_error(DEBUG, "read failed. (maybe EOF or broken)");
                        break;
                }
 
-               if (avcodec_get_type(pFormatCtx->streams[pkt.stream_index]->codecpar->codec_id) == AVMEDIA_TYPE_VIDEO) {
+               if (avcodec_get_type(pFormatCtx->streams[pkt->stream_index]->codecpar->codec_id) == AVMEDIA_TYPE_VIDEO) {
                        v++;
-                       if ((pkt.flags & AV_PKT_FLAG_KEY) || (key_detected == 1)) {
+                       if ((pkt->flags & AV_PKT_FLAG_KEY) || (key_detected == 1)) {
                                debug_msg(RELEASE, "video frame: %d, %d, %d", retry, i, v);
 #ifdef __MMFILE_TEST_MODE__
-                               _dump_av_packet(&pkt);
+                               _dump_av_packet(pkt);
 #endif
                                i++;
                                key_detected = 0;
 
-                               len = avcodec_send_packet(pCodecCtx, &pkt);
+                               len = avcodec_send_packet(pCodecCtx, pkt);
                                if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
                                        debug_error(RELEASE, "Error while avcodec_send_packet[%2d]", len);
                                        break;
@@ -1163,11 +1167,11 @@ static int _get_first_good_video_frame(AVFormatContext *pFormatCtx, AVCodecConte
                        }
                }
 
-               av_packet_unref(&pkt);
+               av_packet_free(&pkt);
        }
 
        /*free pkt after loop breaking*/
-       av_packet_unref(&pkt);
+       av_packet_free(&pkt);
 
        debug_msg(RELEASE, "found: %d, retry: %d", found, retry);
 
index f9e402a..b8d9362 100755 (executable)
@@ -302,7 +302,7 @@ static bool __mmfile_find_proper_frame(AVFormatContext *pFormatCtx,
                                                                                AVFrame *pFrame)
 {
        bool find = false;
-       AVPacket packet;
+       AVPacket *packet;
        AVStream *pStream = NULL;
        bool first_seek = true;
        int64_t pts = 0;
@@ -313,18 +313,19 @@ static bool __mmfile_find_proper_frame(AVFormatContext *pFormatCtx,
 #endif
 
        pStream = pFormatCtx->streams[videoStream];
-       av_init_packet(&packet);
+       packet = av_packet_alloc();
+       mm_file_retvm_if_fails(RELEASE, packet, false);
 
-       while (av_read_frame(pFormatCtx, &packet) >= 0) {
+       while (av_read_frame(pFormatCtx, packet) >= 0) {
 
                /* Is this a packet from the video stream? */
-               if (packet.stream_index == videoStream) {
+               if (packet->stream_index == videoStream) {
                #ifdef __MMFILE_TEST_MODE__
                        debug_msg(RELEASE, "find Video Stream+++++++[%2d]", idx++);
                #endif
 
                        /* Decode video frame*/
-                       len = avcodec_send_packet(pVideoCodecCtx, &packet);
+                       len = avcodec_send_packet(pVideoCodecCtx, packet);
                        if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
                                debug_error(RELEASE, "Error while avcodec_send_packet[%2d]", len);
                                break;
@@ -335,7 +336,7 @@ static bool __mmfile_find_proper_frame(AVFormatContext *pFormatCtx,
                        if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
                                debug_warning(DEBUG, "Error while avcodec_receive_frame");
                        } else if (len >= 0) {
-                               if ((packet.flags & AV_PKT_FLAG_KEY)) {
+                               if ((packet->flags & AV_PKT_FLAG_KEY)) {
 
                                        if (first_seek || !is_accurate) {
                                                /* This is first seeking or not accurate mode.
@@ -355,12 +356,12 @@ static bool __mmfile_find_proper_frame(AVFormatContext *pFormatCtx,
                                } else {
                                        if (is_accurate) {
                                                if (first_seek) {
-                                                       pts = (packet.pts == (int64_t)AV_NOPTS_VALUE) ? (packet.dts * av_q2d(pStream->time_base)) : packet.pts;
+                                                       pts = (packet->pts == (int64_t)AV_NOPTS_VALUE) ? (packet->dts * av_q2d(pStream->time_base)) : packet->pts;
                                                        first_seek = false;
 
                                                        av_seek_frame(pFormatCtx, -1, pos, AVSEEK_FLAG_BACKWARD);
                                                } else {
-                                                       tmpPts = (packet.pts == (int64_t)AV_NOPTS_VALUE) ? (packet.dts * av_q2d(pStream->time_base)) : packet.pts;
+                                                       tmpPts = (packet->pts == (int64_t)AV_NOPTS_VALUE) ? (packet->dts * av_q2d(pStream->time_base)) : packet->pts;
                                                        if (pts == tmpPts)
                                                                find = true;
                                                }
@@ -374,13 +375,11 @@ static bool __mmfile_find_proper_frame(AVFormatContext *pFormatCtx,
                                break;
                }
 
-               /* Free the packet that was allocated by av_read_frame*/
-               av_packet_unref(&packet);
-               av_init_packet(&packet);
+               av_packet_unref(packet);
        }
 
-       /*free pkt after loop breaking*/
-       av_packet_unref(&packet);
+       /*free packet after loop */
+       av_packet_free(&packet);
 
        return find;
 }
index 7f383da..3a26d86 100644 (file)
@@ -1,6 +1,6 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
-Version:    1.0.7
+Version:    1.0.8
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0