Signed-off-by: Vittorio Giovara <[email protected]>
---
This is a small step to allow removing sizeof(AVPacket) from ABI (in the
very very long run), and to investigate what people think of the idea.

There was some discussion in the past and a few founding stone were laid,
this would be mainly a continuation of that work. The goal would be to
have an AVFrame-like structure that can be expanded/modified without
requiring a major bump.

Vittorio

 libavdevice/libdc1394.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c
index 72e2e8b..9327245 100644
--- a/libavdevice/libdc1394.c
+++ b/libavdevice/libdc1394.c
@@ -69,7 +69,7 @@ typedef struct dc1394_data {
     char *pixel_format;     /**< Set by a private option. */
     char *framerate;        /**< Set by a private option. */
 
-    AVPacket packet;
+    AVPacket *packet;
 } dc1394_data;
 
 struct dc1394_frame_format {
@@ -178,15 +178,18 @@ static inline int dc1394_read_common(AVFormatContext *c,
     vst->avg_frame_rate = framerate;
 
     /* packet init */
-    av_init_packet(&dc1394->packet);
-    dc1394->packet.size = av_image_get_buffer_size(fmt->pix_fmt,
-                                                   fmt->width, fmt->height, 1);
-    dc1394->packet.stream_index = vst->index;
-    dc1394->packet.flags |= AV_PKT_FLAG_KEY;
+    dc1394->packet = av_packet_alloc();
+    if (!dc1394->packet)
+        return AVERROR(ENOMEM);
+
+    dc1394->packet->size = av_image_get_buffer_size(fmt->pix_fmt,
+                                                    fmt->width, fmt->height, 
1);
+    dc1394->packet->stream_index = vst->index;
+    dc1394->packet->flags |= AV_PKT_FLAG_KEY;
 
     dc1394->current_frame = 0;
 
-    vst->codecpar->bit_rate = av_rescale(dc1394->packet.size * 8, 
fps->frame_rate, 1000);
+    vst->codecpar->bit_rate = av_rescale(dc1394->packet->size * 8, 
fps->frame_rate, 1000);
     *select_fps = fps;
     *select_fmt = fmt;
 out:
@@ -262,17 +265,17 @@ static int dc1394_v1_read_packet(AVFormatContext *c, 
AVPacket *pkt)
     res = dc1394_dma_single_capture(&dc1394->camera);
 
     if (res == DC1394_SUCCESS) {
-        dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
-        dc1394->packet.pts = (dc1394->current_frame * 1000000) / 
dc1394->frame_rate;
-        res = dc1394->packet.size;
+        dc1394->packet->data = (uint8_t *)(dc1394->camera.capture_buffer);
+        dc1394->packet->pts = (dc1394->current_frame * 1000000) / 
dc1394->frame_rate;
+        res = dc1394->packet->size;
     } else {
         av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
-        dc1394->packet.data = NULL;
         res = -1;
     }
+    if (res < 0)
+        return res;
 
-    *pkt = dc1394->packet;
-    return res;
+    return av_packet_ref(pkt, dc1394->packet);
 }
 
 static int dc1394_v1_close(AVFormatContext * context)
@@ -284,6 +287,8 @@ static int dc1394_v1_close(AVFormatContext * context)
     dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
     dc1394_destroy_handle(dc1394->handle);
 
+    av_packet_free(&dc1394->packet);
+
     return 0;
 }
 
@@ -374,17 +379,17 @@ static int dc1394_v2_read_packet(AVFormatContext *c, 
AVPacket *pkt)
 
     res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, 
&dc1394->frame);
     if (res == DC1394_SUCCESS) {
-        dc1394->packet.data = (uint8_t *) dc1394->frame->image;
-        dc1394->packet.pts  = dc1394->current_frame * 1000000 / 
dc1394->frame_rate;
+        dc1394->packet->data = (uint8_t *) dc1394->frame->image;
+        dc1394->packet->pts  = dc1394->current_frame * 1000000 / 
dc1394->frame_rate;
         res = dc1394->frame->image_bytes;
     } else {
         av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
-        dc1394->packet.data = NULL;
         res = -1;
     }
+    if (res < 0)
+        return res;
 
-    *pkt = dc1394->packet;
-    return res;
+    return av_packet_ref(pkt, dc1394->packet);
 }
 
 static int dc1394_v2_close(AVFormatContext * context)
@@ -396,6 +401,8 @@ static int dc1394_v2_close(AVFormatContext * context)
     dc1394_camera_free(dc1394->camera);
     dc1394_free(dc1394->d);
 
+    av_packet_free(&dc1394->packet);
+
     return 0;
 }
 
-- 
2.9.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to