mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-25 09:32:46 +00:00
Disallow variable number of channels
This commit is contained in:
parent
32eddbe1f3
commit
15c0340eaf
@ -6,6 +6,7 @@
|
|||||||
#import "libswresample/swresample.h"
|
#import "libswresample/swresample.h"
|
||||||
|
|
||||||
@interface FFMpegSWResample () {
|
@interface FFMpegSWResample () {
|
||||||
|
int _sourceChannelCount;
|
||||||
SwrContext *_context;
|
SwrContext *_context;
|
||||||
NSUInteger _ratio;
|
NSUInteger _ratio;
|
||||||
NSInteger _destinationChannelCount;
|
NSInteger _destinationChannelCount;
|
||||||
@ -21,6 +22,7 @@
|
|||||||
- (instancetype)initWithSourceChannelCount:(NSInteger)sourceChannelCount sourceSampleRate:(NSInteger)sourceSampleRate sourceSampleFormat:(enum FFMpegAVSampleFormat)sourceSampleFormat destinationChannelCount:(NSInteger)destinationChannelCount destinationSampleRate:(NSInteger)destinationSampleRate destinationSampleFormat:(enum FFMpegAVSampleFormat)destinationSampleFormat {
|
- (instancetype)initWithSourceChannelCount:(NSInteger)sourceChannelCount sourceSampleRate:(NSInteger)sourceSampleRate sourceSampleFormat:(enum FFMpegAVSampleFormat)sourceSampleFormat destinationChannelCount:(NSInteger)destinationChannelCount destinationSampleRate:(NSInteger)destinationSampleRate destinationSampleFormat:(enum FFMpegAVSampleFormat)destinationSampleFormat {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self != nil) {
|
if (self != nil) {
|
||||||
|
_sourceChannelCount = sourceChannelCount;
|
||||||
_destinationChannelCount = destinationChannelCount;
|
_destinationChannelCount = destinationChannelCount;
|
||||||
_destinationSampleFormat = destinationSampleFormat;
|
_destinationSampleFormat = destinationSampleFormat;
|
||||||
_context = swr_alloc_set_opts(NULL,
|
_context = swr_alloc_set_opts(NULL,
|
||||||
@ -47,6 +49,12 @@
|
|||||||
|
|
||||||
- (NSData * _Nullable)resample:(FFMpegAVFrame *)frame {
|
- (NSData * _Nullable)resample:(FFMpegAVFrame *)frame {
|
||||||
AVFrame *frameImpl = (AVFrame *)[frame impl];
|
AVFrame *frameImpl = (AVFrame *)[frame impl];
|
||||||
|
|
||||||
|
int numChannels = frameImpl->channels;
|
||||||
|
if (numChannels != _sourceChannelCount) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
int bufSize = av_samples_get_buffer_size(NULL,
|
int bufSize = av_samples_get_buffer_size(NULL,
|
||||||
(int)_destinationChannelCount,
|
(int)_destinationChannelCount,
|
||||||
frameImpl->nb_samples * (int)_ratio,
|
frameImpl->nb_samples * (int)_ratio,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user