OSDN Git Service

Merge commit '88434f9725e7c9484dcbcf323566ae88a2904f32'
[android-x86/external-ffmpeg.git] / libavformat / rtpdec_jpeg.c
index b49185a..2553510 100644 (file)
@@ -2,20 +2,20 @@
  * RTP JPEG-compressed Video Depacketizer, RFC 2435
  * Copyright (c) 2012 Samuel Pitoiset
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -101,7 +101,8 @@ static void jpeg_put_marker(PutByteContext *pbc, int code)
 }
 
 static int jpeg_create_header(uint8_t *buf, int size, uint32_t type, uint32_t w,
-                              uint32_t h, const uint8_t *qtable, int nb_qtable)
+                              uint32_t h, const uint8_t *qtable, int nb_qtable,
+                              int dri)
 {
     PutByteContext pbc;
     uint8_t *dht_size_ptr;
@@ -127,6 +128,12 @@ static int jpeg_create_header(uint8_t *buf, int size, uint32_t type, uint32_t w,
     bytestream2_put_byte(&pbc, 0);
     bytestream2_put_byte(&pbc, 0);
 
+    if (dri) {
+        jpeg_put_marker(&pbc, DRI);
+        bytestream2_put_be16(&pbc, 4);
+        bytestream2_put_be16(&pbc, dri);
+    }
+
     /* DQT */
     jpeg_put_marker(&pbc, DQT);
     bytestream2_put_be16(&pbc, 2 + nb_qtable * (1 + 64));
@@ -221,7 +228,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
     const uint8_t *qtables = NULL;
     uint16_t qtable_len;
     uint32_t off;
-    int ret;
+    int ret, dri = 0;
 
     if (len < 8) {
         av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
@@ -237,6 +244,16 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
     buf += 8;
     len -= 8;
 
+    if (type & 0x40) {
+        if (len < 4) {
+            av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
+            return AVERROR_INVALIDDATA;
+        }
+        dri = AV_RB16(buf);
+        buf += 4;
+        len -= 4;
+        type &= ~0x40;
+    }
     /* Parse the restart marker header. */
     if (type > 63) {
         av_log(ctx, AV_LOG_ERROR,
@@ -327,7 +344,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
          * interchange format. */
         jpeg->hdr_size = jpeg_create_header(hdr, sizeof(hdr), type, width,
                                             height, qtables,
-                                            qtable_len / 64);
+                                            qtable_len / 64, dri);
 
         /* Copy JPEG header to frame buffer. */
         avio_write(jpeg->frame, hdr, jpeg->hdr_size);