FFmpeg Input: Enable networking and HLS support...
... also disable use of AudioToolbox codecs, and use only bundled codecs and libfdk-aac for AAC input. This is required for HLS at least, as Apple's system codecs didn't really like the network streams that were provided by HLS streaming stations. Also reshuffle the input priorities between Core Audio input and FFmpeg input, so that they were the way they were before I messed with things a while back. This puts FFmpeg back at the top, using bundled codecs where supported. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
7f114bce0e
commit
2e41e7c525
2 changed files with 93 additions and 100 deletions
|
@ -317,10 +317,7 @@ static SInt64 getSizeProc(void* clientData) {
|
||||||
|
|
||||||
+ (float)priority
|
+ (float)priority
|
||||||
{
|
{
|
||||||
if (@available(macOS 10.15, *))
|
|
||||||
return 1.0;
|
return 1.0;
|
||||||
else
|
|
||||||
return 1.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)fileTypeAssociations
|
+ (NSArray *)fileTypeAssociations
|
||||||
|
|
|
@ -81,8 +81,35 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
totalFrames = 0;
|
totalFrames = 0;
|
||||||
framesRead = 0;
|
framesRead = 0;
|
||||||
|
|
||||||
|
BOOL isStream = NO;
|
||||||
|
|
||||||
// register all available codecs
|
// register all available codecs
|
||||||
|
|
||||||
|
NSURL * url = [s url];
|
||||||
|
if ([[url scheme] isEqualToString:@"http"] ||
|
||||||
|
[[url scheme] isEqualToString:@"https"]) {
|
||||||
|
source = nil;
|
||||||
|
[s close];
|
||||||
|
|
||||||
|
isStream = YES;
|
||||||
|
|
||||||
|
formatCtx = avformat_alloc_context();
|
||||||
|
if (!formatCtx)
|
||||||
|
{
|
||||||
|
ALog(@"Unable to allocate AVFormat context");
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString * urlString = [url absoluteString];
|
||||||
|
if ( (errcode = avformat_open_input(&formatCtx, [urlString UTF8String], NULL, NULL)) < 0 )
|
||||||
|
{
|
||||||
|
char errDescr[4096];
|
||||||
|
av_strerror(errcode, errDescr, 4096);
|
||||||
|
ALog(@"Error opening file, errcode = %d, error = %s", errcode, errDescr);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
buffer = av_malloc(32 * 1024);
|
buffer = av_malloc(32 * 1024);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
|
@ -113,6 +140,7 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
ALog(@"Error opening file, errcode = %d, error = %s", errcode, errDescr);
|
ALog(@"Error opening file, errcode = %d, error = %s", errcode, errDescr);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if((errcode = avformat_find_stream_info(formatCtx, NULL)) < 0)
|
if((errcode = avformat_find_stream_info(formatCtx, NULL)) < 0)
|
||||||
{
|
{
|
||||||
|
@ -166,36 +194,6 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
const AVCodec * codec = NULL;
|
const AVCodec * codec = NULL;
|
||||||
AVDictionary * dict = NULL;
|
AVDictionary * dict = NULL;
|
||||||
|
|
||||||
if (@available(macOS 10.15, *))
|
|
||||||
{
|
|
||||||
switch (codec_id)
|
|
||||||
{
|
|
||||||
case AV_CODEC_ID_MP3:
|
|
||||||
codec = avcodec_find_decoder_by_name("mp3_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_MP2:
|
|
||||||
codec = avcodec_find_decoder_by_name("mp2_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_MP1:
|
|
||||||
codec = avcodec_find_decoder_by_name("mp1_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_AAC:
|
|
||||||
codec = avcodec_find_decoder_by_name("aac_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_ALAC:
|
|
||||||
codec = avcodec_find_decoder_by_name("alac_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_AC3:
|
|
||||||
codec = avcodec_find_decoder_by_name("ac3_at");
|
|
||||||
break;
|
|
||||||
case AV_CODEC_ID_EAC3:
|
|
||||||
codec = avcodec_find_decoder_by_name("eac3_at");
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (codec_id)
|
switch (codec_id)
|
||||||
{
|
{
|
||||||
case AV_CODEC_ID_MP3:
|
case AV_CODEC_ID_MP3:
|
||||||
|
@ -223,7 +221,6 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!codec)
|
if (!codec)
|
||||||
codec = avcodec_find_decoder(codec_id);
|
codec = avcodec_find_decoder(codec_id);
|
||||||
|
@ -405,16 +402,21 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
|
|
||||||
//totalFrames = codecCtx->sample_rate * ((float)formatCtx->duration/AV_TIME_BASE);
|
//totalFrames = codecCtx->sample_rate * ((float)formatCtx->duration/AV_TIME_BASE);
|
||||||
AVRational tb = {.num = 1, .den = codecCtx->sample_rate};
|
AVRational tb = {.num = 1, .den = codecCtx->sample_rate};
|
||||||
totalFrames = av_rescale_q(stream->duration, stream->time_base, tb);
|
totalFrames = isStream ? 0 : av_rescale_q(stream->duration, stream->time_base, tb);
|
||||||
bitrate = (int)((codecCtx->bit_rate) / 1000);
|
bitrate = (int)((codecCtx->bit_rate) / 1000);
|
||||||
framesRead = 0;
|
framesRead = 0;
|
||||||
endOfStream = NO;
|
endOfStream = NO;
|
||||||
endOfAudio = NO;
|
endOfAudio = NO;
|
||||||
|
|
||||||
|
if (!isStream) {
|
||||||
if (stream->start_time && stream->start_time != AV_NOPTS_VALUE)
|
if (stream->start_time && stream->start_time != AV_NOPTS_VALUE)
|
||||||
skipSamples = av_rescale_q(stream->start_time, stream->time_base, tb);
|
skipSamples = av_rescale_q(stream->start_time, stream->time_base, tb);
|
||||||
if (skipSamples < 0)
|
if (skipSamples < 0)
|
||||||
skipSamples = 0;
|
skipSamples = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipSamples = 0;
|
||||||
|
}
|
||||||
|
|
||||||
seekFrame = skipSamples; // Skip preroll if necessary
|
seekFrame = skipSamples; // Skip preroll if necessary
|
||||||
|
|
||||||
|
@ -668,7 +670,7 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
|
|
||||||
+ (NSArray *)mimeTypes
|
+ (NSArray *)mimeTypes
|
||||||
{
|
{
|
||||||
return @[@"application/wma", @"application/x-wma", @"audio/x-wma", @"audio/x-ms-wma", @"audio/x-tak", @"application/ogg", @"audio/aacp", @"audio/mpeg", @"audio/mp4", @"audio/x-mp3", @"audio/x-mp2", @"audio/x-matroska", @"audio/x-ape", @"audio/x-ac3", @"audio/x-dts", @"audio/x-dtshd", @"audio/x-at3", @"audio/wav", @"audio/tta", @"audio/x-tta", @"audio/x-twinvq"];
|
return @[@"application/wma", @"application/x-wma", @"audio/x-wma", @"audio/x-ms-wma", @"audio/x-tak", @"application/ogg", @"audio/aacp", @"audio/mpeg", @"audio/mp4", @"audio/x-mp3", @"audio/x-mp2", @"audio/x-matroska", @"audio/x-ape", @"audio/x-ac3", @"audio/x-dts", @"audio/x-dtshd", @"audio/x-at3", @"audio/wav", @"audio/tta", @"audio/x-tta", @"audio/x-twinvq", @"application/vnd.apple.mpegurl"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)fileTypeAssociations
|
+ (NSArray *)fileTypeAssociations
|
||||||
|
@ -693,13 +695,7 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence)
|
||||||
|
|
||||||
+ (float)priority
|
+ (float)priority
|
||||||
{
|
{
|
||||||
if (@available(macOS 10.15, *))
|
|
||||||
return 1.5;
|
return 1.5;
|
||||||
else
|
|
||||||
return 1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue