OLD | NEW |
1 /* | 1 /* |
2 * Delphine Software International CIN File Demuxer | 2 * Delphine Software International CIN File Demuxer |
3 * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net) | 3 * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net) |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 return 0; | 156 return 0; |
157 } | 157 } |
158 | 158 |
159 static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) | 159 static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) |
160 { | 160 { |
161 CinDemuxContext *cin = s->priv_data; | 161 CinDemuxContext *cin = s->priv_data; |
162 ByteIOContext *pb = s->pb; | 162 ByteIOContext *pb = s->pb; |
163 CinFrameHeader *hdr = &cin->frame_header; | 163 CinFrameHeader *hdr = &cin->frame_header; |
164 int rc, palette_type, pkt_size; | 164 int rc, palette_type, pkt_size; |
| 165 int ret; |
165 | 166 |
166 if (cin->audio_buffer_size == 0) { | 167 if (cin->audio_buffer_size == 0) { |
167 rc = cin_read_frame_header(cin, pb); | 168 rc = cin_read_frame_header(cin, pb); |
168 if (rc) | 169 if (rc) |
169 return rc; | 170 return rc; |
170 | 171 |
171 if ((int16_t)hdr->pal_colors_count < 0) { | 172 if ((int16_t)hdr->pal_colors_count < 0) { |
172 hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count; | 173 hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count; |
173 palette_type = 1; | 174 palette_type = 1; |
174 } else { | 175 } else { |
175 palette_type = 0; | 176 palette_type = 0; |
176 } | 177 } |
177 | 178 |
178 /* palette and video packet */ | 179 /* palette and video packet */ |
179 pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame
_size; | 180 pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame
_size; |
180 | 181 |
181 if (av_new_packet(pkt, 4 + pkt_size)) | 182 ret = av_new_packet(pkt, 4 + pkt_size); |
182 return AVERROR(ENOMEM); | 183 if (ret < 0) |
| 184 return ret; |
183 | 185 |
184 pkt->stream_index = cin->video_stream_index; | 186 pkt->stream_index = cin->video_stream_index; |
185 pkt->pts = cin->video_stream_pts++; | 187 pkt->pts = cin->video_stream_pts++; |
186 | 188 |
187 pkt->data[0] = palette_type; | 189 pkt->data[0] = palette_type; |
188 pkt->data[1] = hdr->pal_colors_count & 0xFF; | 190 pkt->data[1] = hdr->pal_colors_count & 0xFF; |
189 pkt->data[2] = hdr->pal_colors_count >> 8; | 191 pkt->data[2] = hdr->pal_colors_count >> 8; |
190 pkt->data[3] = hdr->video_frame_type; | 192 pkt->data[3] = hdr->video_frame_type; |
191 | 193 |
192 if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size) | 194 ret = get_buffer(pb, &pkt->data[4], pkt_size); |
193 return AVERROR(EIO); | 195 if (ret < 0) { |
| 196 av_free_packet(pkt); |
| 197 return ret; |
| 198 } |
| 199 if (ret < pkt_size) |
| 200 av_shrink_packet(pkt, 4 + ret); |
194 | 201 |
195 /* sound buffer will be processed on next read_packet() call */ | 202 /* sound buffer will be processed on next read_packet() call */ |
196 cin->audio_buffer_size = hdr->audio_frame_size; | 203 cin->audio_buffer_size = hdr->audio_frame_size; |
197 return 0; | 204 return 0; |
198 } | 205 } |
199 | 206 |
200 /* audio packet */ | 207 /* audio packet */ |
201 if (av_new_packet(pkt, cin->audio_buffer_size)) | 208 ret = av_get_packet(pb, pkt, cin->audio_buffer_size); |
202 return AVERROR(ENOMEM); | 209 if (ret < 0) |
| 210 return ret; |
203 | 211 |
204 pkt->stream_index = cin->audio_stream_index; | 212 pkt->stream_index = cin->audio_stream_index; |
205 pkt->pts = cin->audio_stream_pts; | 213 pkt->pts = cin->audio_stream_pts; |
206 cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio
_frame_size; | 214 cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio
_frame_size; |
207 | |
208 if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_s
ize) | |
209 return AVERROR(EIO); | |
210 | |
211 cin->audio_buffer_size = 0; | 215 cin->audio_buffer_size = 0; |
212 return 0; | 216 return 0; |
213 } | 217 } |
214 | 218 |
215 AVInputFormat dsicin_demuxer = { | 219 AVInputFormat dsicin_demuxer = { |
216 "dsicin", | 220 "dsicin", |
217 NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"), | 221 NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"), |
218 sizeof(CinDemuxContext), | 222 sizeof(CinDemuxContext), |
219 cin_probe, | 223 cin_probe, |
220 cin_read_header, | 224 cin_read_header, |
221 cin_read_packet, | 225 cin_read_packet, |
222 }; | 226 }; |
OLD | NEW |