MyCometG3 / DLABridging

Simple Objective-C++ wrapper for Blackmagic DeckLink API (C++ APIs).
MIT License
15 stars 7 forks source link

DLABDevice+Output stopScheduledPlayback ERROR #17

Closed ekiny closed 7 months ago

ekiny commented 7 months ago

I'm trying to send video frames to output of decklink card. Most of them are working good but when I run one of these functions which is needed for releasing frames from buffer when user paused the playback, app crashes. func stopScheduledPlayback() throws func stopScheduledPlayback(inTimeScale timeScale: Int, atTime stopPlayBackAtTime: Int, actualStopTimeAt actualStopTime: UnsafeMutablePointer?) throws

stucks on this line : [delegate scheduledPlaybackHasStoppedOfDevice:wself]; // async

inside this function :

ERROR is : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DLABCapture.OutputManager scheduledPlaybackHasStoppedOfDevice:]: unrecognized selector sent to instance 0x600000135fe0' and Thread 10: "-[DLABCapture.OutputManager scheduledPlaybackHasStoppedOfDevice:]: unrecognized selector sent to instance 0x6000036c62b0"

crash is raised before disableVideoOutput/disableAudioOutput. I had never raised disableVideo functions yet. I'm going step by step.

  1. Prepare Output Device
  2. Create Video/Audio output settings
  3. Enable Video/Audio output AND setup DLABDevice.outputDelegate to your Controller class
  4. Start Audio Preroll
  5. Queue Video/Audio Buffer(s) for preroll
  6. Finish Audio Preroll
  7. Start Scheduled Playback Stream
  8. Queue next video/audio buffer using schedulePlayback() until now everything is working as expected.
  9. Stop Scheduled Playback stream using either ...
MyCometG3 commented 7 months ago

I appreciate your new report.

I think it is a bug of DLABOutputPlaybackDelegate protocol implementation in DLABDevice class. - (void)scheduledPlaybackHasStopped needs to verify that the delegate has @optional method before call it.

Please try to implement one of following. it would solve this issue.

  1. Implement an optional method in your delegate object as an empty function. - (void)scheduledPlaybackHasStoppedOfDevice:(DLABDevice*)sender;

  2. If you can modify the framework code on your side, update DLABDevice+Output.m as following:

    - (void)scheduledPlaybackHasStopped
    {
    // delegate can schedule next frame here
    __weak typeof(self) wself = self;
    id<DLABOutputPlaybackDelegate> delegate = self.outputDelegate;
    [self delegate_async:^{
        if ([delegate respondsToSelector:@selector(scheduledPlaybackHasStoppedOfDevice:)]) {
        [delegate scheduledPlaybackHasStoppedOfDevice:wself]; // async
        }
    }];
    }
ekiny commented 7 months ago

When I update the code with new one, error is not raising. But the problem is: I call "try device.stopScheduledPlayback(inTimeScale: 24000, atTime: frameCounter, actualStopTimeAt: nil) " for releasing buffer frames on device when I paused the video. stopScheduledPlayback does not releasing frames on device. Am I doing something wrong?

INFO ->> I searched Decklink SDK for this and found this code lines for releasing video and audio frames (FilePlayback project): m_deckLinkOutput->StopScheduledPlayback(stopPlaybackAtTime, &stopTime, timeScale); m_deckLinkOutput->FlushBufferedAudioSamples();

MyCometG3 commented 7 months ago

Thank you for your response. I am glad to hear that the original crash issue itself is solved now. I would update the master branch later.

Now I have some question. You seem to expect the visual output signal from the decklink device goes to black out or any visual image like "no signal" etc. Is this correct?

As far as I see the SDK pdf, It seems that:

I hope this would help your issue.

ekiny commented 7 months ago

Thank you for your prompt response. I've made some enhancements to our DLABSandbox SwiftUI project to facilitate better investigation of the issue at hand. Specifically, I've incorporated output classes which I believe will streamline our troubleshooting process.

To access the updated project, please download it from the Google Drive link provided below. Additionally, I've included a test video for playback to help illustrate the problem we're encountering.

[Google Drive Link]

I would greatly appreciate it if you could take some time to review the changes and offer any insights or ideas you may have. Your expertise and collaboration are invaluable as we work towards a resolution.

Thank you once again for your continued effort and support.

MyCometG3 commented 7 months ago

1. I think the original crash problem figured by this issue ticket seems to be fixed by above patch. Is this correct? If so, I would apply the patch into master branch and close this ticket. (The work branch has such update.)

2. I am afraid if you ask me some code based support of your project... Unfortunately I think it is a kind of out-of-scope request. I am sorry I cannot provide such professional support - I am a kind of Sunday programmer.

3. Anyway, I can make some comments per your project code.

Thank you for your great effort. I hope this ticket could help your work.