Added more safety checks and basic seeking support to WMA plugin
parent
132fe98e84
commit
a5d8401477
|
@ -22,6 +22,7 @@
|
|||
int numFrames;
|
||||
int samplePos;
|
||||
|
||||
int streamIndex;
|
||||
AVFormatContext *ic;
|
||||
AVCodecContext *c;
|
||||
AVCodec *codec;
|
||||
|
@ -32,7 +33,7 @@
|
|||
int channels;
|
||||
float frequency;
|
||||
long totalFrames;
|
||||
|
||||
long framesPlayed;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -70,14 +70,21 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
|
|||
return NO;
|
||||
}
|
||||
|
||||
streamIndex = -1;
|
||||
for(i = 0; i < ic->nb_streams; i++) {
|
||||
c = ic->streams[i]->codec;
|
||||
if(c->codec_type == AVMEDIA_TYPE_AUDIO)
|
||||
{
|
||||
NSLog(@"audio codec found");
|
||||
streamIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( streamIndex < 0 ) {
|
||||
NSLog(@"no audio codec found");
|
||||
return NO;
|
||||
}
|
||||
|
||||
avformat_find_stream_info(ic, NULL);
|
||||
|
||||
|
@ -143,7 +150,7 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
|
|||
default:
|
||||
return NO;
|
||||
}
|
||||
totalFrames = c->sample_rate * (ic->duration/1000000LL);
|
||||
totalFrames = c->sample_rate * ((float)ic->duration/AV_TIME_BASE);
|
||||
frequency = c->sample_rate;
|
||||
seekable = YES;
|
||||
|
||||
|
@ -290,7 +297,9 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
|
|||
- (long)seek:(long)frame
|
||||
{
|
||||
NSLog(@"frame: %ld", frame);
|
||||
return 0;
|
||||
AVRational time_base = ic->streams[streamIndex]->time_base;
|
||||
av_seek_frame(ic, streamIndex, frame * time_base.den / time_base.num / frequency, 0);
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue