Added more safety checks and basic seeking support to WMA plugin

CQTexperiment
Chris Moeller 2013-10-03 03:44:39 -07:00
parent 132fe98e84
commit a5d8401477
2 changed files with 13 additions and 3 deletions

View File

@ -22,6 +22,7 @@
int numFrames; int numFrames;
int samplePos; int samplePos;
int streamIndex;
AVFormatContext *ic; AVFormatContext *ic;
AVCodecContext *c; AVCodecContext *c;
AVCodec *codec; AVCodec *codec;
@ -32,7 +33,7 @@
int channels; int channels;
float frequency; float frequency;
long totalFrames; long totalFrames;
long framesPlayed;
} }
@end @end

View File

@ -70,15 +70,22 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
return NO; return NO;
} }
streamIndex = -1;
for(i = 0; i < ic->nb_streams; i++) { for(i = 0; i < ic->nb_streams; i++) {
c = ic->streams[i]->codec; c = ic->streams[i]->codec;
if(c->codec_type == AVMEDIA_TYPE_AUDIO) if(c->codec_type == AVMEDIA_TYPE_AUDIO)
{ {
NSLog(@"audio codec found"); NSLog(@"audio codec found");
streamIndex = i;
break; break;
} }
} }
if ( streamIndex < 0 ) {
NSLog(@"no audio codec found");
return NO;
}
avformat_find_stream_info(ic, NULL); avformat_find_stream_info(ic, NULL);
codec = avcodec_find_decoder(c->codec_id); codec = avcodec_find_decoder(c->codec_id);
@ -143,7 +150,7 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
default: default:
return NO; return NO;
} }
totalFrames = c->sample_rate * (ic->duration/1000000LL); totalFrames = c->sample_rate * ((float)ic->duration/AV_TIME_BASE);
frequency = c->sample_rate; frequency = c->sample_rate;
seekable = YES; seekable = YES;
@ -290,7 +297,9 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op)
- (long)seek:(long)frame - (long)seek:(long)frame
{ {
NSLog(@"frame: %ld", 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;
} }