]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_jpeg.c
mp3dec: read the initial/trailing padding from the LAME tag
[ffmpeg] / libavformat / rtpdec_jpeg.c
index 9f73f7d5dcfd94495a78314c8fa5d3caeff7e61c..bc86b159dea98c0816a43049427448ee7fa8a69f 100644 (file)
  */
 
 #include "avformat.h"
+#include "avio_internal.h"
 #include "rtpdec.h"
 #include "rtpdec_formats.h"
 #include "libavutil/intreadwrite.h"
+#include "libavcodec/jpegtables.h"
 #include "libavcodec/mjpeg.h"
 #include "libavcodec/bytestream.h"
 
@@ -59,25 +61,9 @@ static const uint8_t default_quantizers[128] = {
     99,  99,  99,  99,  99,  99,  99,  99
 };
 
-static PayloadContext *jpeg_new_context(void)
+static void jpeg_close_context(PayloadContext *jpeg)
 {
-    return av_mallocz(sizeof(PayloadContext));
-}
-
-static inline void free_frame_if_needed(PayloadContext *jpeg)
-{
-    if (jpeg->frame) {
-        uint8_t *p;
-        avio_close_dyn_buf(jpeg->frame, &p);
-        av_free(p);
-        jpeg->frame = NULL;
-    }
-}
-
-static void jpeg_free_context(PayloadContext *jpeg)
-{
-    free_frame_if_needed(jpeg);
-    av_free(jpeg);
+    ffio_free_dyn_buf(&jpeg->frame);
 }
 
 static int jpeg_create_huffman_table(PutByteContext *p, int table_class,
@@ -200,16 +186,17 @@ static void create_default_qtables(uint8_t *qtables, uint8_t q)
 {
     int factor = q;
     int i;
+    uint16_t S;
 
     factor = av_clip(q, 1, 99);
 
     if (q < 50)
-        q = 5000 / factor;
+        S = 5000 / factor;
     else
-        q = 200 - factor * 2;
+        S = 200 - factor * 2;
 
     for (i = 0; i < 128; i++) {
-        int val = (default_quantizers[i] * q + 50) / 100;
+        int val = (default_quantizers[i] * S + 50) / 100;
 
         /* Limit the quantizers to 1 <= q <= 255. */
         val = av_clip(val, 1, 255);
@@ -219,7 +206,8 @@ static void create_default_qtables(uint8_t *qtables, uint8_t q)
 
 static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                             const uint8_t *buf, int len, int flags)
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     uint8_t type, q, width, height;
     const uint8_t *qtables = NULL;
@@ -241,12 +229,6 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
     buf += 8;
     len -= 8;
 
-    /* Parse the restart marker header. */
-    if (type > 63) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Unimplemented RTP/JPEG restart marker header.\n");
-        return AVERROR_PATCHWELCOME;
-    }
     if (type > 1) {
         av_log(ctx, AV_LOG_ERROR, "Unimplemented RTP/JPEG type %d\n", type);
         return AVERROR_PATCHWELCOME;
@@ -320,7 +302,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
 
         /* Skip the current frame in case of the end packet
          * has been lost somewhere. */
-        free_frame_if_needed(jpeg);
+        ffio_free_dyn_buf(&jpeg->frame);
 
         if ((ret = avio_open_dyn_buf(&jpeg->frame)) < 0)
             return ret;
@@ -346,7 +328,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
     if (jpeg->timestamp != *timestamp) {
         /* Skip the current frame if timestamp is incorrect.
          * A start packet has been lost somewhere. */
-        free_frame_if_needed(jpeg);
+        ffio_free_dyn_buf(&jpeg->frame);
         av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match.\n");
         return AVERROR_INVALIDDATA;
     }
@@ -370,7 +352,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
         /* Prepare the JPEG packet. */
         if ((ret = ff_rtp_finalize_packet(pkt, &jpeg->frame, st->index)) < 0) {
             av_log(ctx, AV_LOG_ERROR,
-                   "Error occured when getting frame buffer.\n");
+                   "Error occurred when getting frame buffer.\n");
             return ret;
         }
 
@@ -384,8 +366,8 @@ RTPDynamicProtocolHandler ff_jpeg_dynamic_handler = {
     .enc_name          = "JPEG",
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_MJPEG,
-    .alloc             = jpeg_new_context,
-    .free              = jpeg_free_context,
+    .priv_data_size    = sizeof(PayloadContext),
+    .close             = jpeg_close_context,
     .parse_packet      = jpeg_parse_packet,
     .static_payload_id = 26,
 };