From c5a869d406700f81214213de9b225c4ccc182255 Mon Sep 17 00:00:00 2001 From: areff Date: Thu, 28 Feb 2008 05:33:56 +0000 Subject: [PATCH] Some basic WMA code added, reads file properties correctly, code of function tag_recode in asf.c changed due to crasher (this needs to be investigated) --- Frameworks/WMA/ffmpeg-strip-wma/asf.c | 1 + Frameworks/WMA/ffmpeg-strip-wma/futils.c | 6 +- Plugins/WMA/WMA.xcodeproj/project.pbxproj | 6 +- Plugins/WMA/WMADecoder.h | 18 +++- Plugins/WMA/WMADecoder.m | 123 ++++++++++++++++++++++ 5 files changed, 146 insertions(+), 8 deletions(-) diff --git a/Frameworks/WMA/ffmpeg-strip-wma/asf.c b/Frameworks/WMA/ffmpeg-strip-wma/asf.c index 744771232..045737148 100644 --- a/Frameworks/WMA/ffmpeg-strip-wma/asf.c +++ b/Frameworks/WMA/ffmpeg-strip-wma/asf.c @@ -832,6 +832,7 @@ static char *getlocale() static void tag_recode(char *before, unsigned int len) { + return; int result; iconv_t frt; char ansb[len]; diff --git a/Frameworks/WMA/ffmpeg-strip-wma/futils.c b/Frameworks/WMA/ffmpeg-strip-wma/futils.c index 3eefe8b10..3b956c4e7 100644 --- a/Frameworks/WMA/ffmpeg-strip-wma/futils.c +++ b/Frameworks/WMA/ffmpeg-strip-wma/futils.c @@ -399,9 +399,9 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, if (!fmt || must_open_file) { /* if no file needed do not try to open one */ - if (url_fopen(pb, filename, URL_RDONLY) < 0) { - err = AVERROR_IO; - goto fail; + if ((err = url_fopen(pb, filename, URL_RDONLY)) < 0) { + //err = AVERROR_IO; + goto fail; } file_opened = 1; if (buf_size > 0) { diff --git a/Plugins/WMA/WMA.xcodeproj/project.pbxproj b/Plugins/WMA/WMA.xcodeproj/project.pbxproj index 13ffd74fa..6b9abaa52 100644 --- a/Plugins/WMA/WMA.xcodeproj/project.pbxproj +++ b/Plugins/WMA/WMA.xcodeproj/project.pbxproj @@ -19,14 +19,14 @@ isa = PBXContainerItemProxy; containerPortal = B09E95030D748F9B0064F138 /* WMA.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* WMA.framework */; + remoteGlobalIDString = 8DC2EF5B0486A6940098B216; remoteInfo = WMA; }; B09E95450D7496C60064F138 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = B09E95030D748F9B0064F138 /* WMA.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 8DC2EF4F0486A6940098B216 /* WMA Framework */; + remoteGlobalIDString = 8DC2EF4F0486A6940098B216; remoteInfo = "WMA Framework"; }; /* End PBXContainerItemProxy section */ @@ -56,7 +56,6 @@ B09E942E0D747F410064F138 /* WMADecoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMADecoder.m; sourceTree = ""; }; B09E94370D747FAD0064F138 /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../../Audio/Plugin.h; sourceTree = SOURCE_ROOT; }; B09E95030D748F9B0064F138 /* WMA.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = WMA.xcodeproj; path = ../../Frameworks/WMA/WMA.xcodeproj; sourceTree = SOURCE_ROOT; }; - B09E958A0D749E890064F138 /* WMA.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WMA.framework; path = ../../build/Release/WMA.framework; sourceTree = SOURCE_ROOT; }; B09E95F50D74A3ED0064F138 /* Frameworks-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Frameworks-Info.plist"; sourceTree = ""; }; D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -77,7 +76,6 @@ 089C166AFE841209C02AAC07 /* WMA */ = { isa = PBXGroup; children = ( - B09E958A0D749E890064F138 /* WMA.framework */, 08FB77AFFE84173DC02AAC07 /* Classes */, 32C88E010371C26100C91783 /* Other Sources */, 089C167CFE841241C02AAC07 /* Resources */, diff --git a/Plugins/WMA/WMADecoder.h b/Plugins/WMA/WMADecoder.h index 0096389ae..24672adc9 100644 --- a/Plugins/WMA/WMADecoder.h +++ b/Plugins/WMA/WMADecoder.h @@ -9,8 +9,24 @@ #import #import "Plugin.h" -@interface WMADecoder : NSObject { +#import "WMA/avcodec.h" +#import "WMA/avformat.h" +@interface WMADecoder : NSObject +{ + id source; + + AVFormatContext *ic; + AVCodecContext *c; + AVCodec *codec; + + BOOL seekable; + int bitsPerSample; + int bitrate; + int channels; + float frequency; + long totalFrames; + } @end diff --git a/Plugins/WMA/WMADecoder.m b/Plugins/WMA/WMADecoder.m index c4fe76cf2..83606c74e 100644 --- a/Plugins/WMA/WMADecoder.m +++ b/Plugins/WMA/WMADecoder.m @@ -9,7 +9,130 @@ // test #import "WMADecoder.h" +#define ST_BUFF 2048 @implementation WMADecoder + + + +- (BOOL)open:(id)s +{ + source = [s retain]; + + ic = NULL; + av_register_all(); + int err, i; + const char *filename = [[[source url] path] UTF8String]; + int st_buff; + uint8_t *outbuf, *s_outbuf; + + + NSLog(@"lolbots: %s", filename); + + + err = av_open_input_file(&ic, filename, NULL, 0, NULL); + + if (err < 0) + NSLog(@"Opening .WMA file failed horribly: %d", err); + + for(i = 0; i < ic->nb_streams; i++) { + c = &ic->streams[i]->codec; + if(c->codec_type == CODEC_TYPE_AUDIO) + { + NSLog(@"audio codec found"); + break; + } + } + + av_find_stream_info(ic); + + codec = avcodec_find_decoder(c->codec_id); + if (!codec) { + NSLog(@"codec not found"); + return NO; + } + + if (avcodec_open(c, codec) < 0) { + NSLog(@"could not open codec"); + return NO; + } + + st_buff = ST_BUFF; + + outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); + s_outbuf = av_malloc(st_buff); + + dump_format(ic, 0, filename, 0); + + if (ic->title[0] != '\0') + NSLog(@"Title: %s", ic->title); + if (ic->author[0] != '\0') + NSLog(@"Author: %s", ic->author); + if (ic->album[0] != '\0') + NSLog(@"Album: %s", ic->album); + if (ic->year != 0) + NSLog(@"Year: %d", ic->year); + if (ic->track != 0) + NSLog(@"Track: %d", ic->track); + if (ic->genre[0] != '\0') + NSLog(@"Genre: %s", ic->genre); + if (ic->copyright[0] != '\0') + NSLog(@"Copyright: %s", ic->copyright); + if (ic->comment[0] != '\0') + NSLog(@"Comments: %s", ic->comment); + + NSLog(@"bitrate: %d", ic->bit_rate); + return YES; + +} + +- (void)close +{ + avcodec_close(c); + av_close_input_file(ic); + + [source close]; + [source release]; +} + +- (int)readAudio:(void *)buf frames:(UInt32)frames +{ + return 0; + +} + +- (long)seek:(long)frame +{ + return 0; +} + + +- (NSDictionary *)properties +{ + return [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:channels], @"channels", + [NSNumber numberWithInt:bitsPerSample], @"bitsPerSample", + [NSNumber numberWithFloat:frequency], @"sampleRate", + [NSNumber numberWithDouble:totalFrames], @"totalFrames", + [NSNumber numberWithInt:bitrate], @"bitrate", + [NSNumber numberWithBool:([source seekable] && seekable)], @"seekable", + nil]; +} + + ++ (NSArray *)fileTypes +{ + return [NSArray arrayWithObjects:@"wma",nil]; +} + ++ (NSArray *)mimeTypes +{ + return [NSArray arrayWithObjects:@"application/wma", @"application/x-wma", @"audio/x-wma", nil]; +} + + + + + @end