提交 0107f897 编写于 作者: B bbcallen

ios: IJKFF: use concat:// instead of data:// due to url length limit

上级 752ae4b5
......@@ -20,6 +20,8 @@
E66F8DE717EFD9C300354D80 /* IJKFFMoviePlayerController.m in Sources */ = {isa = PBXBuildFile; fileRef = E66F8DE617EFD9C300354D80 /* IJKFFMoviePlayerController.m */; };
E66F8DF117EFEA9400354D80 /* ijkplayer.c in Sources */ = {isa = PBXBuildFile; fileRef = E66F8DEF17EFEA9400354D80 /* ijkplayer.c */; };
E66F8E0317EFEEA400354D80 /* ijkplayer_ios.m in Sources */ = {isa = PBXBuildFile; fileRef = E66F8E0117EFEEA400354D80 /* ijkplayer_ios.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E6716E4B1807E5FC00B3FBC1 /* IJKMediaUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = E6716E4A1807E5FC00B3FBC1 /* IJKMediaUtils.m */; };
E6716E4E1807EA5000B3FBC1 /* IJKFFMrl.m in Sources */ = {isa = PBXBuildFile; fileRef = E6716E4D1807EA5000B3FBC1 /* IJKFFMrl.m */; };
E6903EC217EAF6C500CFD954 /* IJKMediaPlayback.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = E6903EC117EAF6C500CFD954 /* IJKMediaPlayback.h */; };
E6903FC717EAFC2C00CFD954 /* libavcodec.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E6903FC217EAFC2C00CFD954 /* libavcodec.a */; };
E6903FC817EAFC2C00CFD954 /* libavformat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E6903FC317EAFC2C00CFD954 /* libavformat.a */; };
......@@ -94,6 +96,10 @@
E66F8E0117EFEEA400354D80 /* ijkplayer_ios.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ijkplayer_ios.m; path = ijkmedia/ijkplayer/ios/ijkplayer_ios.m; sourceTree = "<group>"; };
E66F8E0217EFEEA400354D80 /* ijkplayer_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ijkplayer_ios.h; path = ijkmedia/ijkplayer/ios/ijkplayer_ios.h; sourceTree = "<group>"; };
E66F8E0517EFEF3900354D80 /* ijksdl_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ijksdl_ios.h; path = ijkmedia/ijksdl/ios/ijksdl_ios.h; sourceTree = "<group>"; };
E6716E491807E5FC00B3FBC1 /* IJKMediaUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IJKMediaUtils.h; path = IJKMediaPlayer/IJKMediaUtils.h; sourceTree = "<group>"; };
E6716E4A1807E5FC00B3FBC1 /* IJKMediaUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IJKMediaUtils.m; path = IJKMediaPlayer/IJKMediaUtils.m; sourceTree = "<group>"; };
E6716E4C1807EA4F00B3FBC1 /* IJKFFMrl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJKFFMrl.h; sourceTree = "<group>"; };
E6716E4D1807EA5000B3FBC1 /* IJKFFMrl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJKFFMrl.m; sourceTree = "<group>"; };
E6903EB917EAF6C500CFD954 /* libIJKMediaPlayer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libIJKMediaPlayer.a; sourceTree = BUILT_PRODUCTS_DIR; };
E6903EC017EAF6C500CFD954 /* IJKMediaPlayer-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IJKMediaPlayer-Prefix.pch"; sourceTree = "<group>"; };
E6903EC117EAF6C500CFD954 /* IJKMediaPlayback.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = IJKMediaPlayback.h; path = IJKMediaPlayer/IJKMediaPlayback.h; sourceTree = "<group>"; };
......@@ -324,6 +330,8 @@
E6903EBE17EAF6C500CFD954 /* IJKFFMoviePlayerController */ = {
isa = PBXGroup;
children = (
E6716E4C1807EA4F00B3FBC1 /* IJKFFMrl.h */,
E6716E4D1807EA5000B3FBC1 /* IJKFFMrl.m */,
E66F8DE517EFD9C300354D80 /* IJKFFMoviePlayerController.h */,
E66F8DE617EFD9C300354D80 /* IJKFFMoviePlayerController.m */,
E6F727B917F2D9D30043623F /* IJKFFMoviePlayerDef.h */,
......@@ -593,6 +601,8 @@
E6903EC117EAF6C500CFD954 /* IJKMediaPlayback.h */,
E6F727C117F7C9B90043623F /* IJKMediaPlayback.m */,
E66F8DC217EECB1E00354D80 /* IJKMediaPlayer.h */,
E6716E491807E5FC00B3FBC1 /* IJKMediaUtils.h */,
E6716E4A1807E5FC00B3FBC1 /* IJKMediaUtils.m */,
);
name = IJKMediaPlayer;
sourceTree = "<group>";
......@@ -675,6 +685,8 @@
E6F727B817F2B1B10043623F /* IJKMediaModule.m in Sources */,
E6F727BB17F2D9D40043623F /* IJKFFMoviePlayerDef.m in Sources */,
E6F727C217F7C9BA0043623F /* IJKMediaPlayback.m in Sources */,
E6716E4B1807E5FC00B3FBC1 /* IJKMediaUtils.m in Sources */,
E6716E4E1807EA5000B3FBC1 /* IJKFFMrl.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -23,9 +23,11 @@
#import "IJKFFMoviePlayerController.h"
#import "IJKFFMoviePlayerDef.h"
#import "IJKMediaPlayback.h"
#import "IJKFFMrl.h"
@implementation IJKFFMoviePlayerController {
NSURL *_url;
IJKFFMrl *_ffMrl;
IjkMediaPlayer *_mediaPlayer;
IJKFFMoviePlayerMessagePool *_msgPool;
......@@ -70,7 +72,8 @@
_initialPlaybackTime = 0;
_endPlaybackTime = 0;
_url = aUrl;
_ffMrl = [[IJKFFMrl alloc] initWithMrl:[aUrl absoluteString]];
_mediaPlayer = ijkmp_ios_create(media_player_msg_loop);
_msgPool = [[IJKFFMoviePlayerMessagePool alloc] init];
......@@ -85,12 +88,17 @@
return self;
}
- (void)dealloc
{
[_ffMrl removeTempFiles];
}
- (void)prepareToPlay
{
if (!_mediaPlayer)
return;
ijkmp_set_data_source(_mediaPlayer, [[_url absoluteString] UTF8String]);
ijkmp_set_data_source(_mediaPlayer, [_ffMrl.resolvedMrl UTF8String]);
ijkmp_set_format_option(_mediaPlayer, "safe", "0"); // for concat demuxer
ijkmp_prepare_async(_mediaPlayer);
}
......
/*
* IJKFFMrl.h
*
* Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/Foundation.h>
@interface IJKFFMrl : NSObject
- (IJKFFMrl *) initWithMrl: (NSString*)aMrl;
- (void) removeTempFiles;
@property(nonatomic, readonly) NSString *rawMrl;
@property(nonatomic, readonly) NSString *resolvedMrl;
@end
/*
* IJKFFMrl.m
*
* Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import "IJKFFMrl.h"
#import "IJKMediaUtils.h"
#include "libavutil/base64.h"
#include "libavutil/mem.h"
@implementation IJKFFMrl {
NSString *_tmpFile;
}
@synthesize rawMrl = _rawMrl;
@synthesize resolvedMrl = _resolvedMrl;
- (IJKFFMrl *)initWithMrl: (NSString*)aMrl
{
self = [super init];
if (self) {
_rawMrl = aMrl;
_resolvedMrl = aMrl;
if ([_rawMrl hasPrefix:@"data://"]) {
NSRange range = [_rawMrl rangeOfString:@","];
if (range.length > 0) {
NSString *data = [_rawMrl substringFromIndex:(range.location + 1)];
NSString *ffConcat = [IJKFFMrl base64Decode:data];
_tmpFile = [IJKMediaUtils createTempFileNameForFFConcat];
[ffConcat writeToFile:_tmpFile
atomically:YES
encoding:NSStringEncodingConversionAllowLossy
error:nil];
_resolvedMrl = [[NSString alloc] initWithFormat:@"concat://%@", _tmpFile];
}
}
if (!_resolvedMrl)
_resolvedMrl = _rawMrl;
}
return self;
}
- (void) removeTempFiles
{
if (_tmpFile) {
[[NSFileManager defaultManager] removeItemAtPath:_tmpFile error:nil];
_tmpFile = nil;
}
}
+ (NSString *) base64Decode: (NSString*)cipher
{
int ret = 0;
const char *utf8Cipher = [cipher UTF8String];
uint8_t *utf8Plain = NULL;
size_t in_size = strlen(utf8Cipher);
size_t out_size = 3 * (in_size / 4) + 1;
if (out_size > INT_MAX || !(utf8Plain = av_malloc(out_size)))
return NULL;
if ((ret = av_base64_decode(utf8Plain, utf8Cipher, out_size)) < 0) {
av_free(utf8Plain);
NSLog(@"Invalid base64 in MRL\n");
return NULL;
}
NSString *plain = [[NSString alloc] initWithUTF8String:(const char *)utf8Plain];
av_free(utf8Plain);
return plain;
}
@end
/*
* IJKMediaUtils.h
*
* Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/Foundation.h>
@interface IJKMediaUtils : NSObject
+ (NSString*)createTempFileNameForFFConcat;
+ (NSString*)createTempFileNameWithPrefix: (NSString*)aPrefix;
+ (NSString*)createTempFileNameInDirectory: (NSString*)aDirectory
withPrefix: (NSString*)aPrefix;
@end
/*
* IJKMediaUtils.m
*
* Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import "IJKMediaUtils.h"
@implementation IJKMediaUtils
+ (NSString*)createTempFileNameForFFConcat
{
return [IJKMediaUtils createTempFileNameWithPrefix:@"ffconcat-"];
}
+ (NSString*)createTempFileNameWithPrefix: (NSString*)aPrefix
{
return [IJKMediaUtils createTempFileNameInDirectory: NSTemporaryDirectory()
withPrefix: aPrefix];
}
+ (NSString*)createTempFileNameInDirectory: (NSString*)aDirectory
withPrefix: (NSString*)aPrefix
{
NSString* templateStr = [NSString stringWithFormat:@"%@/%@XXXXX", aDirectory, aPrefix];
char template[templateStr.length + 1];
strcpy(template, [templateStr cStringUsingEncoding:NSASCIIStringEncoding]);
char* filename = mktemp(template);
if (filename == NULL) {
NSLog(@"Could not create file in directory %@", aDirectory);
return nil;
}
return [NSString stringWithCString:filename encoding:NSASCIIStringEncoding];
}
@end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册