aboutsummaryrefslogtreecommitdiff
path: root/lib/ffmpeg/patches/0018-Setup-wanted-pkt-size-in-spdif-muxers-header-parser.patch
blob: 756a388da4681e3205438b143a21bd274eeb4754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From 6c0fa4c0b23a7ca4888e120d22d6ca95b0254c23 Mon Sep 17 00:00:00 2001
From: Cory Fields <theuni-nospam-@xbmc.org>
Date: Mon, 28 Jun 2010 22:41:33 -0400
Subject: [PATCH 18/32] Setup wanted pkt size in spdif muxers header parser

---
 libavformat/spdif.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/libavformat/spdif.c b/libavformat/spdif.c
index ac84c50..473e325 100644
--- a/libavformat/spdif.c
+++ b/libavformat/spdif.c
@@ -74,7 +74,7 @@ enum IEC958DataType {
 
 typedef struct IEC958Context {
     enum IEC958DataType data_type;  ///< burst info - reference to type of payload of the data-burst
-    int pkt_size;                   ///< length code in bits
+    int pkt_size;                   ///< length code in bytes
     int pkt_offset;                 ///< data burst repetition period in bytes
     uint8_t *buffer;                ///< allocated buffer, used for swap bytes
     int buffer_size;                ///< size of allocated buffer
@@ -110,6 +110,7 @@ static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt)
 
     ctx->data_type  = IEC958_AC3 | (bitstream_mode << 8);
     ctx->pkt_offset = AC3_FRAME_SIZE << 2;
+    ctx->pkt_size   = FFALIGN(pkt->size, 2);
     return 0;
 }
 
@@ -149,6 +150,7 @@ static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
         return -1;
     }
     ctx->pkt_offset = blocks << 7;
+    ctx->pkt_size   = FFALIGN(pkt->size, 2);
 
     return 0;
 }
@@ -184,6 +186,7 @@ static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
         ctx->data_type  = mpeg_data_type [version & 1][layer];
         ctx->pkt_offset = mpeg_pkt_offset[version & 1][layer];
     }
+    ctx->pkt_size = FFALIGN(pkt->size, 2);
     // TODO Data type dependant info (normal/karaoke, dynamic range control)
     return 0;
 }
@@ -202,6 +205,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
         return -1;
     }
 
+    ctx->pkt_size   = FFALIGN(pkt->size, 2);
     ctx->pkt_offset = hdr.samples << 2;
     switch (hdr.num_aac_frames) {
     case 1:
@@ -260,12 +264,15 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     IEC958Context *ctx = s->priv_data;
     int ret, padding;
 
-    ctx->pkt_size = FFALIGN(pkt->size, 2) << 3;
     ret = ctx->header_info(s, pkt);
     if (ret < 0)
         return -1;
+    if (ctx->pkt_size > pkt->size + 1) {
+        av_log(s, AV_LOG_ERROR, "not enough data for requested frame size\n");
+        return -1;
+    }
 
-    padding = (ctx->pkt_offset - BURST_HEADER_SIZE - pkt->size) >> 1;
+    padding = (ctx->pkt_offset - BURST_HEADER_SIZE - ctx->pkt_size) >> 1;
     if (padding < 0) {
         av_log(s, AV_LOG_ERROR, "bitrate is too high\n");
         return -1;
@@ -274,21 +281,18 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     put_le16(s->pb, SYNCWORD1);      //Pa
     put_le16(s->pb, SYNCWORD2);      //Pb
     put_le16(s->pb, ctx->data_type); //Pc
-    put_le16(s->pb, ctx->pkt_size);  //Pd
+    put_le16(s->pb, ctx->pkt_size << 3);  //Pd
 
 #if HAVE_BIGENDIAN
-    put_buffer(s->pb, pkt->data, pkt->size & ~1);
+    put_buffer(s->pb, pkt->data, ctx->pkt_size);
 #else
-    av_fast_malloc(&ctx->buffer, &ctx->buffer_size, pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
+    av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->pkt_size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!ctx->buffer)
         return AVERROR(ENOMEM);
-    bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)pkt->data, pkt->size >> 1);
-    put_buffer(s->pb, ctx->buffer, pkt->size & ~1);
+    bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)pkt->data, ctx->pkt_size >> 1);
+    put_buffer(s->pb, ctx->buffer, ctx->pkt_size);
 #endif
 
-    if (pkt->size & 1)
-        put_be16(s->pb, pkt->data[pkt->size - 1]);
-
     for (; padding > 0; padding--)
         put_be16(s->pb, 0);
 
-- 
1.7.0