Browse code

lavc: skip initial silence when requested

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/07/05 05:03:13
Showing 2 changed files
... ...
@@ -84,6 +84,11 @@ typedef struct AVCodecInternal {
84 84
     unsigned int byte_buffer_size;
85 85
 
86 86
     void *frame_thread_encoder;
87
+
88
+    /**
89
+     * Number of audio samples to skip at the start of the next decoded frame
90
+     */
91
+    int skip_samples;
87 92
 } AVCodecInternal;
88 93
 
89 94
 struct AVCodecDefault {
... ...
@@ -1627,6 +1627,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
1627 1627
     }
1628 1628
 
1629 1629
     if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1630
+        uint8_t *side;
1631
+        int side_size;
1630 1632
         // copy to ensure we do not change avpkt
1631 1633
         AVPacket tmp = *avpkt;
1632 1634
         int did_split = av_packet_split_side_data(&tmp);
... ...
@@ -1645,6 +1647,22 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
1645 1645
                 frame->sample_rate = avctx->sample_rate;
1646 1646
         }
1647 1647
 
1648
+        side= av_packet_get_side_data(avctx->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
1649
+        if(side && side_size>=10) {
1650
+            avctx->internal->skip_samples = AV_RL32(side);
1651
+        }
1652
+        if (avctx->internal->skip_samples) {
1653
+            if(frame->nb_samples <= avctx->internal->skip_samples){
1654
+                *got_frame_ptr = 0;
1655
+                avctx->internal->skip_samples -= frame->nb_samples;
1656
+            } else {
1657
+                av_samples_copy(frame->extended_data, frame->extended_data, 0, avctx->internal->skip_samples,
1658
+                                frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
1659
+                frame->nb_samples -= avctx->internal->skip_samples;
1660
+                avctx->internal->skip_samples = 0;
1661
+            }
1662
+        }
1663
+
1648 1664
         avctx->pkt = NULL;
1649 1665
         if (did_split) {
1650 1666
             ff_packet_free_side_data(&tmp);