[MPlayer-dev-eng] Re: [Mplayer-cvslog] playtree

Alban Bedel albeu at free.fr
Wed Apr 17 12:04:35 CEST 2002


Hi Ponekker Zoltan,

on Tue, 16 Apr 2002 22:32:31 +0200 (CEST) you wrote:

> 
> Albi !
> 
>         play_tree_t * entry = play_tree_new();
>         play_tree_add_file( entry,guiIntfStruct.Filename );
>         if ( playtree ) play_tree_free_list( playtree->child,1 );
>          else playtree=play_tree_new();
>         play_tree_set_child( playtree,entry );
>         if(playtree)
>          {
>           playtree_iter = play_tree_iter_new(playtree,mconfig);
>           if(playtree_iter)
>            {
>             if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
>              {
>               play_tree_iter_free(playtree_iter);
>               playtree_iter = NULL;
>              }
>             filename = play_tree_iter_get_file(playtree_iter,1);
>            }
>          }
> 
> What the problem ? I haven't found it out.

I think you should first always keep the root of the tree and the iterator, don't free them.

On the begining of mplayer.c ensure that both exist from the begining with something like that :

    if(m_config_parse_command_line(mconfig, argc, argv, envp) < 0) exit(1); // error parsing cmdline

    if(!use_gui) // If the tree is empty it will be destroyed : we don't want that
    	playtree = play_tree_cleanup(playtree);
    if(playtree) {
      playtree_iter = play_tree_iter_new(playtree,mconfig);
      if(playtree_iter) {  
	if(play_tree_iter_step(playtree_iter,0,0) == PLAY_TREE_ITER_ENTRY)
		filename = play_tree_iter_get_file(playtree_iter,1);
	else if(!use_gui) { // When we use the gui we need to keep the iter
	  play_tree_iter_free(playtree_iter);
	  playtree_iter = NULL;
	}
      }
    }
	..........
Then I would have done something like that :

      if ( guiIntfStruct.FilenameChanged || !filename )
       {
	play_tree_t * entry;
	// Move the iterator to the root of the tree
	while(play_tree_iter_up_step(playtree_iter,-1,0) != PLAY_TREE_ITER_END)
		/* NOTHING */;
	// Remove the old content
	if(playtree->child) play_tree_free_list( playtree->child,1 );
	// Create the new one
        entry = play_tree_new();
        play_tree_add_file( entry,guiIntfStruct.Filename );
	// Add it in the tree
        play_tree_set_child( playtree,entry );
        if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
	     {
		// It should not happend beacuse we just put something in the tree
		// print an error msg and exit ?
	     }
        filename = play_tree_iter_get_file(playtree_iter,1);
   	guiIntfStruct.FilenameChanged=0;
       } 

It should be better but I didn't tested it (just wrote it here). Anyway I think you shouldn't
use playtree related code in mplayer.c. It was done only for the command line client. It's 
perhaps better to only pass a filename to main loop (like it was before) and move all 
playtree handeling in the GUI ?
BTW I started to write "another mplayer". To do this I took mplayer.c and moved the big
main to a few function and removed all GUI/playtree code. By using this you can then play 
anything in a few function call.
I did this to be able to focus on the interface without messing with the whole code.
First I wrote a command line client wich do the same as the existing one. It only
handle the playtree : 200 lines :)
Now I'm wroking on a GUI using this and libglade. I hope we can share our experiences.

	Albeu



More information about the MPlayer-dev-eng mailing list