From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CD75A402CF for ; Wed, 19 Jan 2022 14:23:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3824B68B0A8; Wed, 19 Jan 2022 16:23:50 +0200 (EET) Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D424868B04D for ; Wed, 19 Jan 2022 16:23:43 +0200 (EET) Received: by mail-qv1-f44.google.com with SMTP id g13so380022qvw.4 for ; Wed, 19 Jan 2022 06:23:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=PKL4bAuKYQ147LNypXPjk4ZSW++nfJ1ICJskGuodgRo=; b=fONo98s7+6va8h7O/Q2xnaMMOWjDFE3jNg4YTzd4bF58Nuak7vRQx4ZgjuHa7GxRw1 8pWHCVdfqzu2l3+DyABaQmFIF22T6tcjgsRV6EOC+3zRQzTImRzqoMohkaJtmkNlK+bs FM4sAa+IwKlie52PoU2ex8Gju2QRVwf64HvwYac45Bnti13HiDvk63wR68qNzEL4Q7Wd RJiiUe4BoAIGeB7TZKtdXDdB5ZGNhc1uJpKoHZBBYAwlicI3aXdPSzkENC7otIUXuiyw 8P2N0UZWI2rd8PrHKlfAStXMDA1/3ZAGezHhXss98IRuCROSCK7sOWuIza5zW3yXhKu5 iAug== X-Gm-Message-State: AOAM5301jjpGAU7HKKFKdQGTy3OJS81Tz67lQXUWdYaHKYzdhL891R3T JDCBdZwMUMOejArMjwmcI4ijiqXvxlzlwgEl X-Google-Smtp-Source: ABdhPJzn6UPq7XrpTLfURvYAQc8RlR5r6szq63hBt9p+MgvQMRNdWLLiG4SQJBjCoOPnstMIIJVYOQ== X-Received: by 2002:ad4:5b8a:: with SMTP id 10mr27574444qvp.63.1642602221635; Wed, 19 Jan 2022 06:23:41 -0800 (PST) Received: from smtpclient.apple ([172.58.4.135]) by smtp.gmail.com with ESMTPSA id w21sm4301940qkp.51.2022.01.19.06.23.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jan 2022 06:23:40 -0800 (PST) From: Romain Beauxis Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_14624158-63DF-417F-8B99-96A9F7402163" Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Date: Wed, 19 Jan 2022 08:23:37 -0600 In-Reply-To: To: FFmpeg development discussions and patches References: X-Mailer: Apple Mail (2.3693.40.0.1.81) Subject: [FFmpeg-devel] [PATCH 1/5] libavdevice/avfoundation.m: use setAudioSettings, extend supported formats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Thilo Borgmann , epirat07@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --Apple-Mail=_14624158-63DF-417F-8B99-96A9F7402163 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This patch switches the logic around audio settings to let the caller = drive the format. After experimenting with the AudioConverter, we realized that, even when = adhering to a strict implementation of the documented API, we were still = getting errors during conversions. The input device would randomly = change from e.g. s32le to s24le between restarts and error out on = conversion (using a freshly initialized converter). Using setAudioSettings allow the OS to drive audio conversion internally = and pick whatever appropriate settings for the audio device. This has = been working very well and is also the way AVFoundation audio input is = setup in videolan. --Apple-Mail=_14624158-63DF-417F-8B99-96A9F7402163 Content-Disposition: attachment; filename=0001-libavdevice-avfoundation.m-use-setAudioSettings-extend.eml Content-Type: message/rfc822; x-unix-mode=0644; name="0001-libavdevice-avfoundation.m-use-setAudioSettings-extend.eml" Content-Transfer-Encoding: quoted-printable =46rom=20fd30f651bdaafe812b5cdc022ef3e4ebd74b6727=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Romain=20Beauxis=20=0A= Date:=20Mon,=2029=20Nov=202021=2008:46:05=20-0600=0ASubject:=20[PATCH]=20= libavdevice/avfoundation.m:=20use=20setAudioSettings,=20extend=0A=20= supported=20formats=0AX-Unsent:=201=0ATo:=20ffmpeg-devel@ffmpeg.org=0A=0A= This=20fixes:=20https://trac.ffmpeg.org/ticket/9502=0A=0ASigned-off-by:=20= Romain=20Beauxis=20=0A---=0A=20= libavdevice/avfoundation.m=20|=20206=20= ++++++++++++-------------------------=0A=201=20file=20changed,=2063=20= insertions(+),=20143=20deletions(-)=0A=0Adiff=20--git=20= a/libavdevice/avfoundation.m=20b/libavdevice/avfoundation.m=0Aindex=20= 0cd6e646d5..77c6e68763=20100644=0A---=20a/libavdevice/avfoundation.m=0A= +++=20b/libavdevice/avfoundation.m=0A@@=20-93,6=20+93,11=20@@=0A=20=20=20= =20=20AVRational=20=20=20=20=20=20framerate;=0A=20=20=20=20=20int=20=20=20= =20=20=20=20=20=20=20=20=20=20width,=20height;=0A=20=0A+=20=20=20=20int=20= =20=20=20=20=20=20=20=20=20=20=20=20channels;=0A+=20=20=20=20int=20=20=20= =20=20=20=20=20=20=20=20=20=20big_endian;=0A+=20=20=20=20int=20=20=20=20=20= =20=20=20=20=20=20=20=20sample_rate;=0A+=20=20=20=20enum=20= AVSampleFormat=20sample_format;=0A+=0A=20=20=20=20=20int=20=20=20=20=20=20= =20=20=20=20=20=20=20capture_cursor;=0A=20=20=20=20=20int=20=20=20=20=20=20= =20=20=20=20=20=20=20capture_mouse_clicks;=0A=20=20=20=20=20int=20=20=20=20= =20=20=20=20=20=20=20=20=20capture_raw_data;=0A@@=20-111,17=20+116,6=20= @@=0A=20=0A=20=20=20=20=20int=20=20=20=20=20=20=20=20=20=20=20=20=20= num_video_devices;=0A=20=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20=20= =20=20=20audio_channels;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20=20= =20=20=20audio_bits_per_sample;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20= =20=20=20=20=20audio_float;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20= =20=20=20=20audio_be;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20=20=20= =20=20audio_signed_integer;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20= =20=20=20=20audio_packed;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20=20= =20=20=20audio_non_interleaved;=0A-=0A-=20=20=20=20int32_t=20=20=20=20=20= =20=20=20=20*audio_buffer;=0A-=20=20=20=20int=20=20=20=20=20=20=20=20=20=20= =20=20=20audio_buffer_size;=0A-=0A=20=20=20=20=20enum=20AVPixelFormat=20= pixel_format;=0A=20=0A=20=20=20=20=20AVCaptureSession=20=20=20=20=20=20=20= =20=20*capture_session;=0A@@=20-298,14=20+292,6=20@@=20static=20void=20= destroy_context(AVFContext*=20ctx)=0A=20=20=20=20=20ctx->audio_output=20=20= =20=20=3D=20NULL;=0A=20=20=20=20=20ctx->avf_delegate=20=20=20=20=3D=20= NULL;=0A=20=20=20=20=20ctx->avf_audio_delegate=20=3D=20NULL;=0A-=0A-=20=20= =20=20av_freep(&ctx->audio_buffer);=0A-=0A-=20=20=20=20= pthread_mutex_destroy(&ctx->frame_lock);=0A-=0A-=20=20=20=20if=20= (ctx->current_frame)=20{=0A-=20=20=20=20=20=20=20=20= CFRelease(ctx->current_frame);=0A-=20=20=20=20}=0A=20}=0A=20=0A=20static=20= void=20parse_device_name(AVFormatContext=20*s)=0A@@=20-671,88=20+657,62=20= @@=20static=20int=20get_video_config(AVFormatContext=20*s)=0A=20static=20= int=20get_audio_config(AVFormatContext=20*s)=0A=20{=0A=20=20=20=20=20= AVFContext=20*ctx=20=3D=20(AVFContext*)s->priv_data;=0A-=20=20=20=20= CMFormatDescriptionRef=20format_desc;=0A-=20=20=20=20AVStream*=20stream=20= =3D=20avformat_new_stream(s,=20NULL);=0A+=20=20=20=20AVStream*=20stream;=0A= +=20=20=20=20int=20bits_per_sample,=20is_float;=0A=20=0A-=20=20=20=20if=20= (!stream)=20{=0A-=20=20=20=20=20=20=20=20return=201;=0A-=20=20=20=20}=0A= +=20=20=20=20enum=20AVCodecID=20codec_id=20=3D=20= av_get_pcm_codec(ctx->sample_format,=20ctx->big_endian);=0A=20=0A-=20=20=20= =20//=20Take=20stream=20info=20from=20the=20first=20frame.=0A-=20=20=20=20= while=20(ctx->audio_frames_captured=20<=201)=20{=0A-=20=20=20=20=20=20=20= =20CFRunLoopRunInMode(kCFRunLoopDefaultMode,=200.1,=20YES);=0A+=20=20=20=20= if=20(codec_id=20=3D=3D=20AV_CODEC_ID_NONE)=20{=0A+=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_ERROR,=20"Error:=20invalid=20sample=20format!\n");=0A= +=20=20=20=20=20=20=20return=20AVERROR(EINVAL);=0A=20=20=20=20=20}=0A=20=0A= -=20=20=20=20lock_frames(ctx);=0A-=0A-=20=20=20=20= ctx->audio_stream_index=20=3D=20stream->index;=0A-=0A-=20=20=20=20= avpriv_set_pts_info(stream,=2064,=201,=20avf_time_base);=0A-=0A-=20=20=20= =20format_desc=20=3D=20= CMSampleBufferGetFormatDescription(ctx->current_audio_frame);=0A-=20=20=20= =20const=20AudioStreamBasicDescription=20*basic_desc=20=3D=20= CMAudioFormatDescriptionGetStreamBasicDescription(format_desc);=0A+=20=20= =20=20switch=20(ctx->sample_format)=20{=0A+=20=20=20=20=20=20=20=20case=20= AV_SAMPLE_FMT_S16:=0A+=20=20=20=20=20=20=20=20=20=20=20=20= bits_per_sample=20=3D=2016;=0A+=20=20=20=20=20=20=20=20=20=20=20=20= is_float=20=3D=200;=0A+=20=20=20=20=20=20=20=20=20=20=20=20break;=0A+=20=20= =20=20=20=20=20=20case=20AV_SAMPLE_FMT_S32:=0A+=20=20=20=20=20=20=20=20=20= =20=20=20bits_per_sample=20=3D=2032;=0A+=20=20=20=20=20=20=20=20=20=20=20= =20is_float=20=3D=200;=0A+=20=20=20=20=20=20=20=20=20=20=20=20break;=0A+=20= =20=20=20=20=20=20=20case=20AV_SAMPLE_FMT_FLT:=0A+=20=20=20=20=20=20=20=20= =20=20=20=20bits_per_sample=20=3D=2032;=0A+=20=20=20=20=20=20=20=20=20=20= =20=20is_float=20=3D=201;=0A+=20=20=20=20=20=20=20=20=20=20=20=20break;=0A= +=20=20=20=20=20=20=20=20default:=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_ERROR,=20"Error:=20invalid=20sample=20format!\n");=0A= +=20=20=20=20=20=20=20=20=20=20=20=20unlock_frames(ctx);=0A+=20=20=20=20=20= =20=20=20=20=20=20=20return=20AVERROR(EINVAL);=0A+=20=20=20=20}=0A=20=0A= -=20=20=20=20if=20(!basic_desc)=20{=0A+=20=20=20=20[ctx->audio_output=20= setAudioSettings:@{=0A+=20=20=20=20=20=20=20=20AVFormatIDKey:=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20@(kAudioFormatLinearPCM),=0A+=20=20=20=20= =20=20=20=20AVLinearPCMBitDepthKey:=20=20=20=20=20=20@(bits_per_sample),=0A= +=20=20=20=20=20=20=20=20AVLinearPCMIsFloatKey:=20=20=20=20=20=20=20= @(is_float),=0A+=20=20=20=20=20=20=20=20AVLinearPCMIsBigEndianKey:=20=20=20= @(ctx->big_endian),=0A+=20=20=20=20=20=20=20=20AVNumberOfChannelsKey:=20=20= =20=20=20=20=20@(ctx->channels),=0A+=20=20=20=20=20=20=20=20= AVLinearPCMIsNonInterleaved:=20@NO,=0A+=20=20=20=20=20=20=20=20= AVSampleRateKey:=20=20=20=20=20=20=20=20=20=20=20=20=20= @(ctx->sample_rate)=0A+=20=20=20=20}];=0A+=0A+=20=20=20=20stream=20=3D=20= avformat_new_stream(s,=20NULL);=0A+=20=20=20=20if=20(!stream)=20{=0A=20=20= =20=20=20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20=20=20=20=20=20= av_log(s,=20AV_LOG_ERROR,=20"audio=20format=20not=20available\n");=0A-=20= =20=20=20=20=20=20=20return=201;=0A+=20=20=20=20=20=20=20=20return=20-1;=0A= =20=20=20=20=20}=0A=20=0A+=20=20=20=20avpriv_set_pts_info(stream,=2064,=20= 1,=20avf_time_base);=0A+=0A=20=20=20=20=20stream->codecpar->codec_type=20= =20=20=20=20=3D=20AVMEDIA_TYPE_AUDIO;=0A-=20=20=20=20= stream->codecpar->sample_rate=20=20=20=20=3D=20basic_desc->mSampleRate;=0A= -=20=20=20=20stream->codecpar->channels=20=20=20=20=20=20=20=3D=20= basic_desc->mChannelsPerFrame;=0A+=20=20=20=20= stream->codecpar->sample_rate=20=20=20=20=3D=20ctx->sample_rate;=0A+=20=20= =20=20stream->codecpar->channels=20=20=20=20=20=20=20=3D=20= ctx->channels;=0A=20=20=20=20=20stream->codecpar->channel_layout=20=3D=20= av_get_default_channel_layout(stream->codecpar->channels);=0A+=20=20=20=20= stream->codecpar->codec_id=20=20=20=20=20=20=20=3D=20codec_id;=0A=20=0A-=20= =20=20=20ctx->audio_channels=20=20=20=20=20=20=20=20=3D=20= basic_desc->mChannelsPerFrame;=0A-=20=20=20=20ctx->audio_bits_per_sample=20= =3D=20basic_desc->mBitsPerChannel;=0A-=20=20=20=20ctx->audio_float=20=20=20= =20=20=20=20=20=20=20=20=3D=20basic_desc->mFormatFlags=20&=20= kAudioFormatFlagIsFloat;=0A-=20=20=20=20ctx->audio_be=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=3D=20basic_desc->mFormatFlags=20&=20= kAudioFormatFlagIsBigEndian;=0A-=20=20=20=20ctx->audio_signed_integer=20=20= =3D=20basic_desc->mFormatFlags=20&=20kAudioFormatFlagIsSignedInteger;=0A= -=20=20=20=20ctx->audio_packed=20=20=20=20=20=20=20=20=20=20=3D=20= basic_desc->mFormatFlags=20&=20kAudioFormatFlagIsPacked;=0A-=20=20=20=20= ctx->audio_non_interleaved=20=3D=20basic_desc->mFormatFlags=20&=20= kAudioFormatFlagIsNonInterleaved;=0A-=0A-=20=20=20=20if=20= (basic_desc->mFormatID=20=3D=3D=20kAudioFormatLinearPCM=20&&=0A-=20=20=20= =20=20=20=20=20ctx->audio_float=20&&=0A-=20=20=20=20=20=20=20=20= ctx->audio_bits_per_sample=20=3D=3D=2032=20&&=0A-=20=20=20=20=20=20=20=20= ctx->audio_packed)=20{=0A-=20=20=20=20=20=20=20=20= stream->codecpar->codec_id=20=3D=20ctx->audio_be=20?=20= AV_CODEC_ID_PCM_F32BE=20:=20AV_CODEC_ID_PCM_F32LE;=0A-=20=20=20=20}=20= else=20if=20(basic_desc->mFormatID=20=3D=3D=20kAudioFormatLinearPCM=20&&=0A= -=20=20=20=20=20=20=20=20ctx->audio_signed_integer=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_bits_per_sample=20=3D=3D=2016=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_packed)=20{=0A-=20=20=20=20=20=20=20=20= stream->codecpar->codec_id=20=3D=20ctx->audio_be=20?=20= AV_CODEC_ID_PCM_S16BE=20:=20AV_CODEC_ID_PCM_S16LE;=0A-=20=20=20=20}=20= else=20if=20(basic_desc->mFormatID=20=3D=3D=20kAudioFormatLinearPCM=20&&=0A= -=20=20=20=20=20=20=20=20ctx->audio_signed_integer=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_bits_per_sample=20=3D=3D=2024=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_packed)=20{=0A-=20=20=20=20=20=20=20=20= stream->codecpar->codec_id=20=3D=20ctx->audio_be=20?=20= AV_CODEC_ID_PCM_S24BE=20:=20AV_CODEC_ID_PCM_S24LE;=0A-=20=20=20=20}=20= else=20if=20(basic_desc->mFormatID=20=3D=3D=20kAudioFormatLinearPCM=20&&=0A= -=20=20=20=20=20=20=20=20ctx->audio_signed_integer=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_bits_per_sample=20=3D=3D=2032=20&&=0A-=20=20=20=20=20= =20=20=20ctx->audio_packed)=20{=0A-=20=20=20=20=20=20=20=20= stream->codecpar->codec_id=20=3D=20ctx->audio_be=20?=20= AV_CODEC_ID_PCM_S32BE=20:=20AV_CODEC_ID_PCM_S32LE;=0A-=20=20=20=20}=20= else=20{=0A-=20=20=20=20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20=20=20= =20=20=20av_log(s,=20AV_LOG_ERROR,=20"audio=20format=20is=20not=20= supported\n");=0A-=20=20=20=20=20=20=20=20return=201;=0A-=20=20=20=20}=0A= -=0A-=20=20=20=20if=20(ctx->audio_non_interleaved)=20{=0A-=20=20=20=20=20= =20=20=20CMBlockBufferRef=20block_buffer=20=3D=20= CMSampleBufferGetDataBuffer(ctx->current_audio_frame);=0A-=20=20=20=20=20= =20=20=20ctx->audio_buffer_size=20=20=20=20=20=20=20=20=3D=20= CMBlockBufferGetDataLength(block_buffer);=0A-=20=20=20=20=20=20=20=20= ctx->audio_buffer=20=20=20=20=20=20=20=20=20=20=20=20=20=3D=20= av_malloc(ctx->audio_buffer_size);=0A-=20=20=20=20=20=20=20=20if=20= (!ctx->audio_buffer)=20{=0A-=20=20=20=20=20=20=20=20=20=20=20=20= unlock_frames(ctx);=0A-=20=20=20=20=20=20=20=20=20=20=20=20av_log(s,=20= AV_LOG_ERROR,=20"error=20allocating=20audio=20buffer\n");=0A-=20=20=20=20= =20=20=20=20=20=20=20=20return=201;=0A-=20=20=20=20=20=20=20=20}=0A-=20=20= =20=20}=0A-=0A-=20=20=20=20CFRelease(ctx->current_audio_frame);=0A-=20=20= =20=20ctx->current_audio_frame=20=3D=20nil;=0A+=20=20=20=20= ctx->audio_stream_index=20=3D=20stream->index;=0A=20=0A=20=20=20=20=20= unlock_frames(ctx);=0A-=0A=20=20=20=20=20return=200;=0A=20}=0A=20=0A@@=20= -975,6=20+935,7=20@@=20static=20int=20avf_read_header(AVFormatContext=20= *s)=0A=20=20=20=20=20=20=20=20=20goto=20fail;=0A=20=20=20=20=20}=0A=20=20= =20=20=20if=20(audio_device=20&&=20add_audio_device(s,=20audio_device))=20= {=0A+=20=20=20=20=20=20=20=20goto=20fail;=0A=20=20=20=20=20}=0A=20=0A=20=20= =20=20=20[ctx->capture_session=20startRunning];=0A@@=20-1048,6=20+1009,7=20= @@=20static=20int=20copy_cvpixelbuffer(AVFormatContext=20*s,=0A=20=0A=20= static=20int=20avf_read_packet(AVFormatContext=20*s,=20AVPacket=20*pkt)=0A= =20{=0A+=20=20=20=20OSStatus=20ret;=0A=20=20=20=20=20AVFContext*=20ctx=20= =3D=20(AVFContext*)s->priv_data;=0A=20=0A=20=20=20=20=20do=20{=0A@@=20= -1091,7=20+1053,7=20@@=20static=20int=20avf_read_packet(AVFormatContext=20= *s,=20AVPacket=20*pkt)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20status=20=3D=20copy_cvpixelbuffer(s,=20image_buffer,=20pkt);=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20}=20else=20{=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20status=20=3D=200;=0A-=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20OSStatus=20ret=20=3D=20= CMBlockBufferCopyDataBytes(block_buffer,=200,=20pkt->size,=20pkt->data);=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20ret=20=3D=20= CMBlockBufferCopyDataBytes(block_buffer,=200,=20pkt->size,=20pkt->data);=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20(ret=20!=3D=20= kCMBlockBufferNoErr)=20{=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20status=20=3D=20AVERROR(EIO);=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20}=0A@@=20-1105,19=20+1067,17=20@@=20static=20int=20= avf_read_packet(AVFormatContext=20*s,=20AVPacket=20*pkt)=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20}=0A=20=20=20=20=20=20=20=20=20}=20else=20if=20= (ctx->current_audio_frame=20!=3D=20nil)=20{=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20CMBlockBufferRef=20block_buffer=20=3D=20= CMSampleBufferGetDataBuffer(ctx->current_audio_frame);=0A-=20=20=20=20=20= =20=20=20=20=20=20=20int=20block_buffer_size=20=20=20=20=20=20=20=20=20=3D= =20CMBlockBufferGetDataLength(block_buffer);=0A=20=0A-=20=20=20=20=20=20=20= =20=20=20=20=20if=20(!block_buffer=20||=20!block_buffer_size)=20{=0A-=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20return=20AVERROR(EIO);=0A-=20=20=20= =20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20=20=20=20=20= size_t=20buffer_size=20=3D=20CMBlockBufferGetDataLength(block_buffer);=0A= =20=0A-=20=20=20=20=20=20=20=20=20=20=20=20if=20= (ctx->audio_non_interleaved=20&&=20block_buffer_size=20>=20= ctx->audio_buffer_size)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20int=20= status=20=3D=20av_new_packet(pkt,=20buffer_size);=0A+=20=20=20=20=20=20=20= =20=20=20=20=20if=20(status=20<=200)=20{=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20return=20AVERROR_BUFFER_TOO_SMALL;=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20return=20status;=0A=20=20=20=20=20=20=20=20= =20=20=20=20=20}=0A=20=0A-=20=20=20=20=20=20=20=20=20=20=20=20if=20= (av_new_packet(pkt,=20block_buffer_size)=20<=200)=20{=0A+=20=20=20=20=20=20= =20=20=20=20=20=20ret=20=3D=20CMBlockBufferCopyDataBytes(block_buffer,=20= 0,=20pkt->size,=20pkt->data);=0A+=20=20=20=20=20=20=20=20=20=20=20=20if=20= (ret=20!=3D=20kCMBlockBufferNoErr)=20{=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20unlock_frames(ctx);=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20return=20AVERROR(EIO);=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20}=0A@@=20-1133,54=20+1093,10=20@@=20static=20int=20= avf_read_packet(AVFormatContext=20*s,=20AVPacket=20*pkt)=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20pkt->stream_index=20=20=3D=20= ctx->audio_stream_index;=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= pkt->flags=20=20=20=20=20=20=20=20|=3D=20AV_PKT_FLAG_KEY;=0A=20=0A-=20=20= =20=20=20=20=20=20=20=20=20=20if=20(ctx->audio_non_interleaved)=20{=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20int=20sample,=20c,=20shift,=20= num_samples;=0A-=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= OSStatus=20ret=20=3D=20CMBlockBufferCopyDataBytes(block_buffer,=200,=20= pkt->size,=20ctx->audio_buffer);=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20if=20(ret=20!=3D=20kCMBlockBufferNoErr)=20{=0A-=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return=20= AVERROR(EIO);=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=0A-=0A= -=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20num_samples=20=3D=20= pkt->size=20/=20(ctx->audio_channels=20*=20(ctx->audio_bits_per_sample=20= >>=203));=0A-=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20//=20= transform=20decoded=20frame=20into=20output=20format=0A-=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20#define=20INTERLEAVE_OUTPUT(bps)=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20{=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= int##bps##_t=20**src;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20int##bps##_t=20*dest;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20src=20=3D=20av_malloc(ctx->audio_channels=20*=20= sizeof(int##bps##_t*));=20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20if=20(!src)=20{=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= unlock_frames(ctx);=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20return=20AVERROR(EIO);=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= }=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20for=20(c=20=3D=200;=20c=20<=20ctx->audio_channels;=20c++)=20{=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A= -=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= src[c]=20=3D=20((int##bps##_t*)ctx->audio_buffer)=20+=20c=20*=20= num_samples;=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20}=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20dest=20=20=3D=20= (int##bps##_t*)pkt->data;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20shift=20=3D=20bps=20-=20= ctx->audio_bits_per_sample;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20for=20(sample=20=3D=200;=20sample=20<=20= num_samples;=20sample++)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20\=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20for=20(c=20=3D=200;=20c=20<=20ctx->audio_channels;=20c++)=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= *dest++=20=3D=20src[c][sample]=20<<=20shift;=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20av_freep(&src);=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20\=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20}=0A-=0A-=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20if=20(ctx->audio_bits_per_sample=20<=3D=2016)=20{=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= INTERLEAVE_OUTPUT(16)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= }=20else=20{=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20INTERLEAVE_OUTPUT(32)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20}=0A-=20=20=20=20=20=20=20=20=20=20=20=20}=20else=20{=0A-=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20OSStatus=20ret=20=3D=20= CMBlockBufferCopyDataBytes(block_buffer,=200,=20pkt->size,=20pkt->data);=0A= -=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20(ret=20!=3D=20= kCMBlockBufferNoErr)=20{=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20unlock_frames(ctx);=0A-=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20return=20AVERROR(EIO);=0A-=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20}=0A-=20=20=20=20=20=20=20=20=20=20=20=20}=0A-=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20= CFRelease(ctx->current_audio_frame);=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20ctx->current_audio_frame=20=3D=20nil;=0A+=0A+=20=20=20=20=20=20=20=20=20= =20=20=20unlock_frames(ctx);=0A=20=20=20=20=20=20=20=20=20}=20else=20{=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20pkt->data=20=3D=20NULL;=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20unlock_frames(ctx);=0A@@=20-1205,6=20= +1121,10=20@@=20static=20int=20avf_close(AVFormatContext=20*s)=0A=20}=0A=20= =0A=20static=20const=20AVOption=20options[]=20=3D=20{=0A+=20=20=20=20{=20= "channels",=20"number=20of=20audio=20channels",=20offsetof(AVFContext,=20= channels),=20AV_OPT_TYPE_INT,=20{.i64=3D2},=200,=20INT_MAX,=20= AV_OPT_FLAG_ENCODING_PARAM=20},=0A+=20=20=20=20{=20"sample_rate",=20= "audio=20sample=20rate",=20offsetof(AVFContext,=20sample_rate),=20= AV_OPT_TYPE_INT,=20{.i64=3D44100},=200,=20INT_MAX,=20= AV_OPT_FLAG_ENCODING_PARAM=20},=0A+=20=20=20=20{=20"big_endian",=20= "return=20big=20endian=20samples=20for=20audio=20data",=20= offsetof(AVFContext,=20big_endian),=20AV_OPT_TYPE_BOOL,=20{.i64=3D0},=20= 0,=201,=20AV_OPT_FLAG_ENCODING_PARAM=20},=0A+=20=20=20=20{=20= "sample_format",=20"audio=20sample=20format",=20offsetof(AVFContext,=20= sample_format),=20AV_OPT_TYPE_INT,=20{.i64=3DAV_SAMPLE_FMT_S16},=200,=20= INT_MAX,=20AV_OPT_FLAG_ENCODING_PARAM=20},=0A=20=20=20=20=20{=20= "list_devices",=20"list=20available=20devices",=20offsetof(AVFContext,=20= list_devices),=20AV_OPT_TYPE_BOOL,=20{.i64=3D0},=200,=201,=20= AV_OPT_FLAG_DECODING_PARAM=20},=0A=20=20=20=20=20{=20= "video_device_index",=20"select=20video=20device=20by=20index=20for=20= devices=20with=20same=20name=20(starts=20at=200)",=20= offsetof(AVFContext,=20video_device_index),=20AV_OPT_TYPE_INT,=20{.i64=20= =3D=20-1},=20-1,=20INT_MAX,=20AV_OPT_FLAG_DECODING_PARAM=20},=0A=20=20=20= =20=20{=20"audio_device_index",=20"select=20audio=20device=20by=20index=20= for=20devices=20with=20same=20name=20(starts=20at=200)",=20= offsetof(AVFContext,=20audio_device_index),=20AV_OPT_TYPE_INT,=20{.i64=20= =3D=20-1},=20-1,=20INT_MAX,=20AV_OPT_FLAG_DECODING_PARAM=20},=0A--=20=0A= 2.32.0=20(Apple=20Git-132)=0A=0A= --Apple-Mail=_14624158-63DF-417F-8B99-96A9F7402163 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --Apple-Mail=_14624158-63DF-417F-8B99-96A9F7402163--