Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: mschneider on January 16, 2008, 08:28:30 PM

Title: converting char* to char *
Post by: mschneider on January 16, 2008, 08:28:30 PM
I'm switching between two different plugins with the audio stopped, and I'm trying to retain some ID3 information. What I'm doing is stopping the audio and saving the path of the currently playing track as a file. I then enter the plugin and try to load ID3 information about the stopped file from the saved path. The functions i am using take different pointers though and the strings seem to be incompatible.

Here is the information saving:
Code: [Select]
struct mp3entry *id3 = audio_current_track();
fd = rb->open("./path.txt", O_RDWR|O_CREAT);
rb->fdprintf(fd, id3->path);
rb->close(fd);
audio_stop();

I then try to read the line of the file with the path into a buffer and then use that path to get the id3 information with rb->mp3info.

Code: [Select]
char* buf;
char *buf2;
struct mp3entry *id3

fd = rb->open("./path.txt", O_RDONLY);
rb->read_line(fd, buf, 150);
buf2 = buf;
rb->mp3info(*id3, buf2);

The read_line function takes char* buf though and the rb->mp3info function takes char *filename. Is there any way to do this?
Title: Re: converting char* to char *
Post by: saratoga on January 16, 2008, 09:03:42 PM

The read_line function takes char* buf though and the rb->mp3info function takes char *filename. Is there any way to do this?

Both of those have type "char *".  "buf" and "filename" are just variable names, not types themselves.  Have you tried printing buf ?  My guess is it contains something other then the file path and therefore the call to mp3info() fails, but I'm not really sure.
Title: Re: converting char* to char *
Post by: mschneider on January 17, 2008, 07:26:11 PM
I have tried nearly everything I can think of. Everything either says that the pointer is without a cast or prints nothing into the buffer. Are there any other ways to load the Id3 information of a stopped track?
Title: Re: converting char* to char *
Post by: GodEater on January 18, 2008, 03:27:26 AM
Looking at your code again, I don't think it's the char* that's causing the error message you're seeing, I think it's your id3 struct.

You have :
Code: [Select]
struct mp3entry *id3

rb->mp3info(*id3, buf2);

And what I *think* you should have is :

Code: [Select]
struct mp3entry id3;

rb->mp3info(&id3, buf2);
Title: Re: converting char* to char *
Post by: LinusN on January 18, 2008, 03:36:16 AM
GodEater is correct. Check out apps/plugins/properties.c to see how it is done.
Title: Re: converting char* to char *
Post by: linuxstb on January 18, 2008, 03:42:11 AM
Also, (as you can see in properties.c), you should use the more general get_metadata() function on the swcodec targets (i.e. everything apart from Archos), and mp3info for hwcodec (i.e. Archos).

EDIT: Your call to read_line is also wrong - it will write into the buffer pointed to by "buf", but it doesn't point anywhere...  Instead of declaring buf as "char* buf", you should declare it as "char buf[MAX_PATH];".
Title: Re: converting char* to char *
Post by: GodEater on January 18, 2008, 03:55:06 AM
...and looking again, in your first post, I see you have two definitions of your id3 struct.

First you had :
Code: [Select]
struct mp3entry *id3 = audio_current_track();

and then further down you had:
Code: [Select]
struct mp3entry *id3;    //although yours was missing the ';' :D

The first one is ok, because the audio_current_track() call sorts out getting the memory that the id3* pointer is "looking" at.

The second one (I assume in another function? Although it's hard to tell without seeing all your code) *isn't* okay - because all you've said is "this is a pointer", you've not actually got it pointing to any memory anywhere.

So either you need to pass the value obtained from the first call to audio_current_track() into the second definition of id3 somehow, or do the call again.

And in any event, when you have it defined as a pointer, when you end up calling mp3info() - (although don't - do what linuxstb said!) - you do it like this :

Code: [Select]
rb->mp3info(id3,buf2);      // i.e. without the '*' on the front of id3

Using the '*' tells the compiler to dereference the pointer (i.e. use what it's pointing at), and you just want the value of the pointer itself to go to mp3info (i.e. where it's pointing).
Title: Re: converting char* to char *
Post by: mschneider on January 18, 2008, 09:14:44 PM
First off, thanks for all of your help. I've tried doing what you advised and as far as I can tell it should work for what I am trying to accomplish - but I've run into a few compiler warnings. Here's my entire code (the first section in my first post refers to how I am saving the path of the currently playing file), this is how I am trying to access the ID3 information:
Code: [Select]
int goto_track(void)
{


    int fd;
    char* current_track[MAX_PATH];
    struct mp3entry id3;

    fd = rb->open(TEMP_PATH, O_RDONLY);
    rb->read_line(fd, current_track, MAX_PATH);
    rb->close(fd);  
    fd = rb->open(current_track, O_RDONLY);
#if (CONFIG_CODEC == SWCODEC)
    if (fd >= 0 && rb->get_metadata(&id3, fd, current_track))
#else
    if (!rb->mp3info(&id3, current_track));
#endif
    rb->close(fd);

}

Here are the compiler warnings I am getting:

Code: [Select]
CC tesplugin.c
testplugin.c: In function 'goto_track':
testplugin.c:375: warning: passing argument 2 of 'rb->read_line' from incompatible pointer type
testplugin.c:377: warning: passing argument 1 of 'rb->open' from incompatible pointer type
testplugin.c:379: warning: passing argument 3 of 'rb->get_metadata' from incompatible pointer type
testplugin.c:385: warning: control reaches end of non-void function
LD testplugin.elf
OBJCOPY testplugin.rock
MAKE in shortcuts
make[3]: Nothing to be done for `all

Again, thanks for all the help.
Title: Re: converting char* to char *
Post by: linuxstb on January 19, 2008, 04:04:17 AM
You've defined "current_track" to be an array of pointers to char.

It should be "char current_track[MAX_PATH]";

The last warning is because you've defined your function to be of type "int" - meaning that it should return an integer (e.g. you could use 0 for success, -1 for failure).