Revision d1e0d21f libavformat/thp.c

View differences:

libavformat/thp.c
35 35
    int              next_frame;
36 36
    int              next_framesz;
37 37
    int              video_stream_index;
38
    int              audio_stream_index;
38 39
    int              compcount;
39 40
    unsigned char    components[16];
40 41
    AVStream*        vst;
41 42
    int              has_audio;
43
    int              audiosize;
42 44
} ThpDemuxContext;
43 45

  
44 46

  
......
116 118
             get_be32(pb); /* Unknown.  */
117 119
        }
118 120
      else if (thp->components[i] == 1) {
119
          /* XXX: Required for audio playback.  */
121
          if (thp->has_audio != 0)
122
              break;
123

  
124
          /* Audio component.  */
125
          st = av_new_stream(s, 0);
126
          if (!st)
127
              return AVERROR_NOMEM;
128

  
129
          st->codec->codec_type = CODEC_TYPE_AUDIO;
130
          st->codec->codec_id = CODEC_ID_ADPCM_THP;
131
          st->codec->codec_tag = 0;  /* no fourcc */
132
          st->codec->channels    = get_be32(pb); /* numChannels.  */
133
          st->codec->sample_rate = get_be32(pb); /* Frequency.  */
134

  
135
          av_set_pts_info(st, 64, 1, st->codec->sample_rate);
136

  
137
          thp->audio_stream_index = st->index;
120 138
          thp->has_audio = 1;
121 139
      }
122 140
    }
......
132 150
    int size;
133 151
    int ret;
134 152

  
153
    if (thp->audiosize == 0) {
154

  
135 155
    /* Terminate when last frame is reached.  */
136 156
    if (thp->frame >= thp->framecnt)
137 157
       return AVERROR_IO;
......
145 165
                        get_be32(pb); /* Previous total size.  */
146 166
    size              = get_be32(pb); /* Total size of this frame.  */
147 167

  
168
    /* Store the audiosize so the next time this function is called,
169
       the audio can be read.  */
148 170
    if (thp->has_audio)
149
                        get_be32(pb); /* Audio size.  */
171
        thp->audiosize = get_be32(pb); /* Audio size.  */
172
    else
173
        thp->frame++;
150 174

  
151 175
    ret = av_get_packet(pb, pkt, size);
152 176
    if (ret != size) {
......
155 179
    }
156 180

  
157 181
    pkt->stream_index = thp->video_stream_index;
158
    thp->frame++;
182
    }
183
    else {
184
        ret = av_get_packet(pb, pkt, thp->audiosize);
185
        if (ret != thp->audiosize) {
186
            av_free_packet(pkt);
187
            return AVERROR_IO;
188
        }
189

  
190
        pkt->stream_index = thp->audio_stream_index;
191
        thp->audiosize = 0;
192
        thp->frame++;
193
    }
159 194

  
160 195
    return 0;
161 196
}

Also available in: Unified diff