]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_jpeg.c
aacdec: Lower the number of frames required to detect ADTS
[ffmpeg] / libavformat / rtpdec_jpeg.c
index 9dd5f68764686ce0c29c5e24e4f37fb334442fee..ed9c86ceb960359a66223474c60dba1ec7d94a6a 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "avformat.h"
+#include "rtpdec.h"
 #include "rtpdec_formats.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/mjpeg.h"
@@ -218,7 +219,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;
@@ -246,6 +248,10 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
                "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;
+    }
 
     /* Parse the quantization table header. */
     if (off == 0) {
@@ -303,6 +309,14 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
                 qtables    = &jpeg->qtables[q - 128][0];
                 qtable_len =  jpeg->qtables_len[q - 128];
             }
+        } else { /* q <= 127 */
+            if (q == 0 || q > 99) {
+                av_log(ctx, AV_LOG_ERROR, "Reserved q value %d\n", q);
+                return AVERROR_INVALIDDATA;
+            }
+            create_default_qtables(new_qtables, q);
+            qtables    = new_qtables;
+            qtable_len = sizeof(new_qtables);
         }
 
         /* Skip the current frame in case of the end packet
@@ -313,12 +327,6 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
             return ret;
         jpeg->timestamp = *timestamp;
 
-        if (!qtables) {
-            create_default_qtables(new_qtables, q);
-            qtables    = new_qtables;
-            qtable_len = sizeof(new_qtables);
-        }
-
         /* Generate a frame and scan headers that can be prepended to the
          * RTP/JPEG data payload to produce a JPEG compressed image in
          * interchange format. */
@@ -361,19 +369,11 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
         avio_write(jpeg->frame, buf, sizeof(buf));
 
         /* Prepare the JPEG packet. */
-        av_init_packet(pkt);
-        pkt->size = avio_close_dyn_buf(jpeg->frame, &pkt->data);
-        if (pkt->size < 0) {
+        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");
-            jpeg->frame = NULL;
-            return pkt->size;
+                   "Error occurred when getting frame buffer.\n");
+            return ret;
         }
-        pkt->stream_index = st->index;
-        pkt->destruct     = av_destruct_packet;
-
-        /* Re-init the frame buffer. */
-        jpeg->frame = NULL;
 
         return 0;
     }