Skip to content

Commit 2811ea2

Browse files
committed
fix(video_player): improve audio track format handling in tests
- Simplified mock format descriptions in VideoPlayerTests to prevent Core Media crashes - Removed unnecessary mock format description setup that could cause test instability - Updated format description validation to only accept genuine Core Media objects, removing NSObject fallback - Fixed potential crash when accessing format descriptions in test environment
1 parent 1161332 commit 2811ea2

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,9 @@ - (void)testGetAudioTracksWithRegularAssetTracks {
10581058
OCMStub([mockTrack2 languageCode]).andReturn(@"es");
10591059
OCMStub([mockTrack2 estimatedDataRate]).andReturn(96000.0f);
10601060

1061-
// Mock format descriptions for track 1
1062-
id mockFormatDesc1 = OCMClassMock([NSObject class]);
1063-
AudioStreamBasicDescription asbd1 = {0};
1064-
asbd1.mSampleRate = 48000.0;
1065-
asbd1.mChannelsPerFrame = 2;
1066-
1067-
OCMStub([mockTrack1 formatDescriptions]).andReturn(@[ mockFormatDesc1 ]);
1061+
// Mock empty format descriptions to avoid Core Media crashes in test environment
1062+
OCMStub([mockTrack1 formatDescriptions]).andReturn(@[]);
1063+
OCMStub([mockTrack2 formatDescriptions]).andReturn(@[]);
10681064

10691065
// Mock the asset to return our tracks
10701066
NSArray *mockTracks = @[ mockTrack1, mockTrack2 ];

packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,9 @@ - (nullable FVPNativeAudioTrackData *)getAudioTracks:(FlutterError *_Nullable *_
580580
NSString *className = NSStringFromClass([formatDescObj class]);
581581

582582
// Only process objects that are clearly Core Media format descriptions
583-
// This works for both real CMFormatDescription objects and properly configured mock
584-
// objects
585583
if ([className hasPrefix:@"CMAudioFormatDescription"] ||
586584
[className hasPrefix:@"CMVideoFormatDescription"] ||
587-
[className hasPrefix:@"CMFormatDescription"] ||
588-
[formatDescObj
589-
isKindOfClass:[NSObject
590-
class]]) { // Allow mock objects that inherit from NSObject
585+
[className hasPrefix:@"CMFormatDescription"]) {
591586

592587
CMFormatDescriptionRef formatDesc = (__bridge CMFormatDescriptionRef)formatDescObj;
593588

0 commit comments

Comments
 (0)