Code Monkey home page Code Monkey logo

Comments (11)

myrmidon-media avatar myrmidon-media commented on May 18, 2024

Proposed Patch:

+ int player_create_callback(struct Player *player) {
+   static const AVIOInterruptCB int_cb = {interrupt_cb, NULL};
+   player->input_format_ctx->interrupt_callback = int_cb;
+   player->input_format_ctx->interrupt_callback.opaque = player;
+      //Some verification here
+   return 0;
+ }



+ static int interrupt_cb (void *p)
+ {
+    struct Player *player = (struct Player*) p;
+    if(player->exit_called){
+      return 1;
+    }
+   return 0;
+ }

struct Player {
   .....
    int caputre_streams_no;
+  int exit_called;
    int video_stream_no;
   ....

}


void player_stop(struct State * state) {
    int ret;
+   state->player->exit_called = 1;
    pthread_mutex_lock(&state->player->mutex_operation);
    player_stop_without_lock(state);
    pthread_mutex_unlock(&state->player->mutex_operation);
}

int player_set_data_source(struct State *state, const char *file_path,
        AVDictionary *dictionary, int video_stream_no, int audio_stream_no,
        int subtitle_stream_no) { 

....

+ if ((err = player_create_callback(player)) < 0)
+       goto error;

...
}

from androidffmpeg.

jacek-marchwicki avatar jacek-marchwicki commented on May 18, 2024

This looks god - but there should be added some synchronization mechanism - some mutex to prevent read/write exit_called from different threads, and to ensure that this variable is pushed between two cpu's units. Probably I will try to fis this tomorrow. But I do not have testing environment - we use ffmpeg only via wifi. But you will be able to check.

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

Perfect, if there's anything I can help just let me know

from androidffmpeg.

jacek-marchwicki avatar jacek-marchwicki commented on May 18, 2024

Sorry for late answer.. I have a lot to do in other project.
This is fix, try it please because I do not have time to test it. https://review.appunite.com/3993

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

(Please Ignore my last messages)

After heavy testing the problem was a simple pthread_mutex_unlock(&player->mutex_interrupt); before returning 1 :)

static int player_ctx_interrupt_callback(void *p) {
    struct Player *player = (struct Player*) p;
    pthread_mutex_lock(&player->mutex_interrupt);
    if (player->interrupt) {
                //Don't forget to unlock
        pthread_mutex_unlock(&player->mutex_interrupt);
        return 1;
    }
    pthread_mutex_unlock(&player->mutex_interrupt);
    return 0;
}

from androidffmpeg.

jacek-marchwicki avatar jacek-marchwicki commented on May 18, 2024

sorry for ugly bug.
Last time I wrote to much code with java "synchronize (obj) {}", "try {} finally {}" style ;)

Fixed https://review.appunite.com/#/c/3993/

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

The most obvious bugs are always the most difficult to spot :)

Beware that patch set 2 is the same as patch set 1 don't forget to add the pthread_mutex_unlock(&player->mutex_interrupt);

from androidffmpeg.

jacek-marchwicki avatar jacek-marchwicki commented on May 18, 2024

It is quite different

int player_ctx_interrupt_callback(void *p) {
    int ret = 0;
    struct Player *player = (struct Player*) p;
    pthread_mutex_lock(&player->mutex_interrupt);
    if (player->interrupt) {
        // method is interrupt
        ret = 1; // <- no return just assign variable
    }
    pthread_mutex_unlock(&player->mutex_interrupt);
    return ret;
}

"The most obvious bugs are always the most difficult to spot :)" - true

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

Ooops I didn't notice the subtle change :)

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

Another hang occurs if we call player_stop() while player_open_input() is running as AVIOInterrupt doesn't handle callbacks on avformat_open_input()

The hang happens because of:

void player_stop_without_lock(struct State * state) {
....
    //playing false so we return and don't execute closing procedure
      if (!player->playing)
        return;
....
}

Maybe adding another check:

if (!player->playing && !player->setting_data_source)
        return;

What do you think jacek?

from androidffmpeg.

myrmidon-media avatar myrmidon-media commented on May 18, 2024

A possible solution:

void player_stop(struct State * state) {
    int ret;

    struct Player * player = state->player;

    pthread_mutex_lock(&player->mutex_interrupt);
    player->interrupt = TRUE;
    pthread_mutex_unlock(&player->mutex_interrupt);

+   if(!player->input_inited){
+        //If locking thread a minimal block occurs but exits, not sure what to do
+       //pthread_mutex_lock(&player->mutex_operation);
+       player_open_input_free(player);
+       //pthread_mutex_unlock(&player->mutex_operation);
+   }

    else{
        pthread_mutex_lock(&player->mutex_operation);
        player_stop_without_lock(state);
        pthread_mutex_unlock(&player->mutex_operation);
    }
}



int player_set_data_source(){

....

if ((err = player_open_input(player, file_path, dictionary)) < 0)
        goto error;

+ else if (player->interrupt && !player->input_inited)
+       goto error;

...
}

from androidffmpeg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.