Revision ede0e475 ffmpeg.c

View differences:

ffmpeg.c
1174 1174
{
1175 1175
    AVFormatContext *os;
1176 1176
    AVOutputStream *ost;
1177
    uint8_t *ptr;
1178
    int len, ret, i;
1177
    int ret, i;
1179 1178
    uint8_t *data_buf;
1180 1179
    int data_size, got_picture;
1181 1180
    AVFrame picture;
......
1184 1183
    static short *samples= NULL;
1185 1184
    AVSubtitle subtitle, *subtitle_to_free;
1186 1185
    int got_subtitle;
1186
    AVPacket avpkt;
1187

  
1188
    av_init_packet(&avpkt);
1187 1189

  
1188 1190
    if(ist->next_pts == AV_NOPTS_VALUE)
1189 1191
        ist->next_pts= ist->pts;
1190 1192

  
1191 1193
    if (pkt == NULL) {
1192 1194
        /* EOF handling */
1193
        ptr = NULL;
1194
        len = 0;
1195
        avpkt.data = NULL;
1196
        avpkt.size = 0;
1195 1197
        goto handle_eof;
1196 1198
    }
1197 1199

  
1198 1200
    if(pkt->dts != AV_NOPTS_VALUE)
1199 1201
        ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
1200 1202

  
1201
    len = pkt->size;
1202
    ptr = pkt->data;
1203
    avpkt.size = pkt->size;
1204
    avpkt.data = pkt->data;
1203 1205

  
1204 1206
    //while we have more to decode or while the decoder did output something on EOF
1205
    while (len > 0 || (!pkt && ist->next_pts != ist->pts)) {
1207
    while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) {
1206 1208
    handle_eof:
1207 1209
        ist->pts= ist->next_pts;
1208 1210

  
1209
        if(len && len != pkt->size && verbose>0)
1211
        if(avpkt.size && avpkt.size != pkt->size && verbose>0)
1210 1212
            fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
1211 1213

  
1212 1214
        /* decode the packet if needed */
......
1224 1226
                data_size= samples_size;
1225 1227
                    /* XXX: could avoid copy if PCM 16 bits with same
1226 1228
                       endianness as CPU */
1227
                ret = avcodec_decode_audio2(ist->st->codec, samples, &data_size,
1228
                                           ptr, len);
1229
                ret = avcodec_decode_audio3(ist->st->codec, samples, &data_size,
1230
                                            &avpkt);
1229 1231
                if (ret < 0)
1230 1232
                    goto fail_decode;
1231
                ptr += ret;
1232
                len -= ret;
1233
                avpkt.data += ret;
1234
                avpkt.size -= ret;
1233 1235
                /* Some bug in mpeg audio decoder gives */
1234 1236
                /* data_size < 0, it seems they are overflows */
1235 1237
                if (data_size <= 0) {
......
1245 1247
                    /* XXX: allocate picture correctly */
1246 1248
                    avcodec_get_frame_defaults(&picture);
1247 1249

  
1248
                    ret = avcodec_decode_video(ist->st->codec,
1249
                                               &picture, &got_picture, ptr, len);
1250
                    ret = avcodec_decode_video2(ist->st->codec,
1251
                                                &picture, &got_picture, &avpkt);
1250 1252
                    ist->st->quality= picture.quality;
1251 1253
                    if (ret < 0)
1252 1254
                        goto fail_decode;
......
1260 1262
                                          ist->st->codec->time_base.num * ticks) /
1261 1263
                            ist->st->codec->time_base.den;
1262 1264
                    }
1263
                    len = 0;
1265
                    avpkt.size = 0;
1264 1266
                    break;
1265 1267
            case CODEC_TYPE_SUBTITLE:
1266
                ret = avcodec_decode_subtitle(ist->st->codec,
1267
                                              &subtitle, &got_subtitle, ptr, len);
1268
                ret = avcodec_decode_subtitle2(ist->st->codec,
1269
                                               &subtitle, &got_subtitle, &avpkt);
1268 1270
                if (ret < 0)
1269 1271
                    goto fail_decode;
1270 1272
                if (!got_subtitle) {
1271 1273
                    goto discard_packet;
1272 1274
                }
1273 1275
                subtitle_to_free = &subtitle;
1274
                len = 0;
1276
                avpkt.size = 0;
1275 1277
                break;
1276 1278
            default:
1277 1279
                goto fail_decode;
......
1291 1293
                }
1292 1294
                break;
1293 1295
            }
1294
            data_buf = ptr;
1295
            data_size = len;
1296
            ret = len;
1297
            len = 0;
1296
            data_buf = avpkt.data;
1297
            data_size = avpkt.size;
1298
            ret = avpkt.size;
1299
            avpkt.size = 0;
1298 1300
        }
1299 1301

  
1300 1302
        buffer_to_free = NULL;

Also available in: Unified diff