Skip to content

Commit

Permalink
Add random repeat option to ffmpeg movie player
Browse files Browse the repository at this point in the history
Fix pause/play state tracking bugs in ffmpeg movie player config dialog.
Properly reset the "is_ready" flag when closing a ffmpeg movie item
Fix potential div0 error in Downmixer
Provide default needsSetup method for compressors
  • Loading branch information
zakk4223 committed Apr 11, 2020
1 parent 55c111f commit ae02cd7
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 38 deletions.
19 changes: 12 additions & 7 deletions CSFFMpegCapturePlugin/CSFFMpegCapturePlugin/CSFFMpegCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,20 @@ -(void)itemStarted:(CSFFMpegInput *)item
[CATransaction commit];
}];
}
self.durationString = [self timeToString:item.duration];
self.currentMovieDuration = item.duration;
[self generateUniqueID];
self.captureName = item.shortName;
if (self.pcmPlayer)
if (item)
{
self.pcmPlayer.name = item.shortName;
self.durationString = [self timeToString:item.duration];
self.currentMovieDuration = item.duration;
[self generateUniqueID];
self.captureName = item.shortName;
if (self.pcmPlayer)
{
self.pcmPlayer.name = item.shortName;
}
[self changeAttachedAudioInputName:self.uuid withName:item.shortName];
} else {
self.currentTimeString = [self timeToString:0.0f];
}
[self changeAttachedAudioInputName:self.uuid withName:item.shortName];
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (void)viewDidLoad {
// Do view setup here.
if (self.captureObj && self.captureObj.player)
{
[self pauseStateChanged];
self.captureObj.player.pauseStateChanged = ^{
[self pauseStateChanged];
};
Expand Down Expand Up @@ -220,7 +221,7 @@ - (IBAction)manualAddItem:(id)sender
-(void)pauseStateChanged
{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.captureObj.player.paused)
if (self.captureObj.player.paused || !self.captureObj.player.playing)
{
NSImage *playImage = [[NSBundle bundleForClass:[self class]] imageForResource:@"play"];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -23,7 +23,7 @@
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vOl-es-UsB">
<rect key="frame" x="35" y="285" width="286" height="19"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="aCx-uQ-Hyw">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -46,12 +46,12 @@
<tableColumns>
<tableColumn width="513" minWidth="40" maxWidth="1000" id="Nwb-J9-jgx">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" controlSize="small" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="w0V-n1-Avc">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -64,7 +64,7 @@
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="D02-lA-vKn">
<rect key="frame" x="0.0" y="3" width="475" height="14"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="InC-Ai-kHU">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand Down Expand Up @@ -107,7 +107,7 @@
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SXP-7Z-utT">
<rect key="frame" x="-2" y="62" width="52" height="14"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="4Uo-PT-atT">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -121,7 +121,7 @@
<constraint firstAttribute="width" constant="52" id="dWY-0y-GBb"/>
</constraints>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="geK-QL-6Yn">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -145,15 +145,9 @@
<segments>
<segment image="NSRemoveTemplate"/>
<segment image="rewind" tag="1"/>
<segment image="play">
<nil key="label"/>
</segment>
<segment image="fastforward">
<nil key="label"/>
</segment>
<segment width="268" enabled="NO" tag="4">
<nil key="label"/>
</segment>
<segment image="play"/>
<segment image="fastforward"/>
<segment width="268" enabled="NO" tag="4"/>
</segments>
</segmentedCell>
<connections>
Expand All @@ -166,7 +160,7 @@
<constraint firstAttribute="width" constant="28" id="Lsw-A7-SMg"/>
</constraints>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Add:" id="p7M-Xi-1dn">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -177,15 +171,15 @@
<constraint firstAttribute="width" constant="48" id="9j3-Jz-aMG"/>
</constraints>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Playing:" id="b9z-O4-d9f">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Taf-5T-FT6">
<rect key="frame" x="54" y="326" width="466" height="14"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="jIY-LY-9hI">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -197,7 +191,7 @@
<rect key="frame" x="324" y="279" width="47" height="27"/>
<buttonCell key="cell" type="push" title="Add" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="VLP-Wp-4UT">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<action selector="manualAddItem:" target="-2" id="b7q-4K-5mv"/>
Expand All @@ -207,7 +201,7 @@
<rect key="frame" x="369" y="279" width="65" height="27"/>
<buttonCell key="cell" type="push" title="Browse" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Vlz-7L-vXD">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<action selector="chooseFile:" target="-2" id="upc-a7-d92"/>
Expand All @@ -217,7 +211,7 @@
<rect key="frame" x="-3" y="37" width="96" height="20"/>
<buttonCell key="cell" type="check" title="Play when live" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="meK-YV-QDR">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<binding destination="oEH-Pr-eH8" name="value" keyPath="selection.playWhenLive" id="SP5-JY-yC1"/>
Expand All @@ -230,7 +224,7 @@
</constraints>
<buttonCell key="cell" type="check" title="Use current position" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="c7q-Ze-6Qj">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<binding destination="oEH-Pr-eH8" name="value" keyPath="selection.useCurrentPosition" id="gTJ-ii-Wob"/>
Expand All @@ -239,7 +233,7 @@
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IEf-UH-Kgb">
<rect key="frame" x="242" y="39" width="41" height="14"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Repeat" id="rDX-h9-STO">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -251,12 +245,15 @@
</constraints>
<popUpButtonCell key="cell" type="push" title="None" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="UbH-Gg-9jj" id="sQk-jw-qzF">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
<menu key="menu" id="lru-RP-mX3">
<items>
<menuItem title="None" state="on" id="UbH-Gg-9jj"/>
<menuItem title="All" tag="2" id="cg5-NZ-cE9"/>
<menuItem title="Current" tag="1" id="x9J-aD-GCG"/>
<menuItem title="Random" tag="3" id="hyQ-vC-rp9" userLabel="Random">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
Expand All @@ -268,7 +265,7 @@
<rect key="frame" x="-3" y="17" width="139" height="20"/>
<buttonCell key="cell" type="check" title="Deactivate when done" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="13y-lB-coZ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="label" size="11"/>
</buttonCell>
<connections>
<binding destination="oEH-Pr-eH8" name="value" keyPath="selection.deactivateWhenDone" id="NSA-6h-jfT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ -(void)closeMedia
{
@synchronized (self) {
_stop_request = YES;

_is_ready = NO;
dispatch_semaphore_signal(_read_loop_semaphore);

av_thread_message_queue_set_err_send(_video_message_queue, AVERROR_EOF);
Expand Down
3 changes: 2 additions & 1 deletion CSFFMpegCapturePlugin/CSFFMpegCapturePlugin/CSFFMpegPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
typedef enum ff_movie_repeat_t {
kCSFFMovieRepeatNone = 0,
kCSFFMovieRepeatOne = 1,
kCSFFMovieRepeatAll = 2
kCSFFMovieRepeatAll = 2,
kCSFFMovieRepeatRandom = 3
} ff_movie_repeat;


Expand Down
20 changes: 20 additions & 0 deletions CSFFMpegCapturePlugin/CSFFMpegCapturePlugin/CSFFMpegPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ -(CSFFMpegInput *)nextItem
if (self.repeat == kCSFFMovieRepeatNone || self.repeat == kCSFFMovieRepeatAll)
{
currentIdx++;
} else if (self.repeat == kCSFFMovieRepeatRandom) {
currentIdx = arc4random_uniform(_inputQueue.count);
}

}
Expand Down Expand Up @@ -638,8 +640,17 @@ -(void)inputDone
CSFFMpegInput *willPlay = nil;
CSFFMpegInput *wasPlaying = self.currentlyPlaying;




if (_audio_done && _video_done)
{


if (wasPlaying)
{
[wasPlaying seek:0.0f];
}

//[self.currentlyPlaying stop];

Expand All @@ -657,8 +668,17 @@ -(void)inputDone

if (!willPlay && (willPlay != wasPlaying))
{
self.playing = NO;
if (self.pauseStateChanged)
{
dispatch_async(dispatch_get_main_queue(), ^{
self.pauseStateChanged();
});
}

if (self.itemStarted)
{

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.itemStarted(nil);});
}

Expand Down
2 changes: 1 addition & 1 deletion CocoaSplit/CAMultiAudio/CAMultiAudioDownmixer.m
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ -(void)didInitializeNode
NSLog(@"Failed to set output volume for channel %d on %@ with status %d", chan, self, err);
}

if (_inputChannels < self.graph.audioFormat.channelCount)
if ((_inputChannels > 0) && _inputChannels < self.graph.audioFormat.channelCount)
{
UInt32 inChan = chan % _inputChannels;
[self setVolume:1.0f forChannel:inChan outChannel:chan];
Expand Down
5 changes: 5 additions & 0 deletions CocoaSplit/Compressor/CompressorBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ -(bool)compressFrame:(CapturedFrameData *)frameData
}


-(bool)needsSetup
{
return NO;
}


-(void)reconfigureCompressor
{
Expand Down

0 comments on commit ae02cd7

Please sign in to comment.