Revision 7fc8f7f1 src/Chunkiser/output-stream-play.c

View differences:

src/Chunkiser/output-stream-play.c
253 253
  return 1;
254 254
}
255 255

  
256
static int audio_write_packet(struct dechunkiser_ctx *o, AVPacket *op)
256
static int audio_write_packet(struct dechunkiser_ctx *o, AVPacket pkt)
257 257
{
258 258
  int res; 
259
  AVPacket *pkt, pkt1;
260 259
  AVFormatContext * s1=o->outctx;
261 260
  int size_out;
262 261
  int data_size=AVCODEC_MAX_AUDIO_FRAME_SIZE,len1;
263 262
  void *outbuf, *buffer_resample;
264 263

  
265
  pkt1 = *op;
266
  pkt = &pkt1;
267

  
268
  if (pkt->size == 0) {
264
  if (pkt.size == 0) {
269 265
    return 0;
270 266
  }
271 267

  
......
281 277
  if (o->rsc == NULL) {
282 278
    snd_pcm_format_t snd_pcm_fmt;
283 279

  
284
    snd_pcm_fmt = sample_fmt_to_snd_pcm_format(o->outctx->streams[pkt->stream_index]->codec->sample_fmt);
280
    snd_pcm_fmt = sample_fmt_to_snd_pcm_format(o->outctx->streams[pkt.stream_index]->codec->sample_fmt);
285 281
    if (snd_pcm_fmt==SND_PCM_FORMAT_UNKNOWN){
286 282
      fprintf (stderr, "sample format not supported\n");
287 283

  
......
289 285
    }
290 286
    
291 287
    if (prepare_audio(o->playback_handle, snd_pcm_fmt, o->channels, &o->sample_rate) >= 0) {
292
      o->rsc = av_audio_resample_init(o->outctx->streams[pkt->stream_index]->codec->channels,
293
                                      o->outctx->streams[pkt->stream_index]->codec->channels,
288
      o->rsc = av_audio_resample_init(o->outctx->streams[pkt.stream_index]->codec->channels,
289
                                      o->outctx->streams[pkt.stream_index]->codec->channels,
294 290
                                      o->sample_rate,
295
                                      o->outctx->streams[pkt->stream_index]->codec->sample_rate,
296
                                      o->outctx->streams[pkt->stream_index]->codec->sample_fmt,
297
                                      o->outctx->streams[pkt->stream_index]->codec->sample_fmt, 16, 10, 0, 0.8);
291
                                      o->outctx->streams[pkt.stream_index]->codec->sample_rate,
292
                                      o->outctx->streams[pkt.stream_index]->codec->sample_fmt,
293
                                      o->outctx->streams[pkt.stream_index]->codec->sample_fmt, 16, 10, 0, 0.8);
298 294
    } else {
299 295
      return -2;
300 296
    }
301 297
  }
302 298

  
303
  while (pkt->size > 0) { 
299
  while (pkt.size > 0) { 
304 300
    outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE * 8);	/* FIXME: Why "* 8"? */
305 301
    buffer_resample = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE * 8);
306 302
    data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE * 2;		/* FIXME: Shouldn't this be "* 8" too? */
307 303

  
308
    len1 = avcodec_decode_audio3(s1->streams[pkt->stream_index]->codec, (int16_t *)outbuf, &data_size, pkt);
304
    len1 = avcodec_decode_audio3(s1->streams[pkt.stream_index]->codec, (int16_t *)outbuf, &data_size, &pkt);
309 305
    if (len1 < 0) {
310 306
      fprintf(stderr, "Error while decoding\n"); 
311 307

  
......
313 309
    }
314 310

  
315 311
    if(data_size > 0) {
316
      data_size /= s1->streams[pkt->stream_index]->codec->channels * pow(2, s1->streams[pkt->stream_index]->codec->sample_fmt); // FIXME: Remove the "pow()"
312
      data_size /= s1->streams[pkt.stream_index]->codec->channels * pow(2, s1->streams[pkt.stream_index]->codec->sample_fmt); // FIXME: Remove the "pow()"
317 313
      size_out = audio_resample(o->rsc, buffer_resample, outbuf, data_size); 
318 314
      //size_out/= s1->streams[pkt->stream_index]->codec->channels*pow(2,s1->streams[pkt->stream_index]->codec->sample_fmt);
319 315
   
......
321 317
      if (res < 0) { 
322 318
        snd_pcm_recover(o->playback_handle, res, 0);
323 319
      } else if(res == size_out) {	// FIXME: WTF?
324
        pkt->size -= len1;
325
        pkt->data += len1;
320
        pkt.size -= len1;
321
        pkt.data += len1;
326 322
      }
327 323
    }
328 324
    av_free(outbuf);
......
492 488
      }
493 489
      if(difft>=0) {
494 490
        usleep(difft);
495
        audio_write_packet(o, &pkt);
491
        audio_write_packet(o, pkt);
496 492
      }
497 493
      av_free(pkt.data);
498 494
      av_free_packet(&pkt);

Also available in: Unified diff