|
From: Daniel T. <dt....@gm...> - 2011-06-22 06:51:16
|
I've debugged it a bit an I think I've found the problem.
I did some comparing between my copy of libmpeg compiled for my computer and the compiled copy for my ARM processor.
I found that STATE_INTERNAL_NORETURN was defined as ((mpeg2_state_t)-1). On x86 processors, gcc makes the mpeg2_state_t enumeration a signed type while on my ARM processor, it's an unsigned type. So, because -1 is cast to an unsigned type, it's value (in my case) was 255 instead of -1. That probably was the reason why it worked on my computer and not my ARM processor. I simply changed the cast to a signed character type and recompiled.
Now, I'm getting, presumably, a stack overflow somewhere on the second call to mpeg_parse() (after calling mpeg_buffer()). If anyone can shed some light, that would be great.
On 15/06/2011, at 4:38 PM, Daniel Tang wrote:
> Hi,
>
> I've just compiled libmpeg2 for an embedded platform and have written some code for decoding. But the call to mpeg2_parse in this code seems to always return STATE_INVALID.
>
> int play(FILE * mpgfile)
> {
> mpeg2dec_t * decoder;
> const mpeg2_info_t * info;
> mpeg2_state_t state;
> size_t size = 1;
> unsigned char *buffer = malloc(BUFFER_SIZE);
>
> char debug[20];
> if (!buffer) {
> show_msgbox("NspireMoviePlayer","NULL ptr from Malloc");
> return 1;
> }
>
> decoder = mpeg2_init ();
> if (!decoder) {
> show_msgbox("NspireMoviePlayer","Could not init mpeg2");
> return 1;
> }
>
> info = mpeg2_info (decoder);
> do
> {
> state = mpeg2_parse (decoder);
> switch (state) {
> case STATE_BUFFER:
> size = fread (buffer, 1, BUFFER_SIZE, mpgfile);
> mpeg2_buffer (decoder, buffer, buffer + size);
> break;
> case STATE_SEQUENCE:
> mpeg2_convert (decoder, mpeg2convert_rgb24, NULL);
> settimerperiod(info->sequence->frame_period);
> break;
> case STATE_SLICE:
> case STATE_END:
> if (info->sequence->width != SCREEN_WIDTH ||
> info->sequence->height != SCREEN_HEIGHT)
> {
> show_msgbox("NspireMoviePlayer","Screen size mismatch");
> goto die;
> }
> else {
> waittimerperiod();
> renderframe(info->display_fbuf->buf[0]);
> }
> break;
> case STATE_INVALID:
> goto die;
> break;
> default:
> break;
> }
> } while(size);
>
> mpeg2_close(decoder);
> return 0;
>
> die:
> mpeg2_close(decoder);
> return 1;
> }
>
> I dug around decode.c and added some debugging messages and it seems it's conking out in this piece of code at the bottom of mpeg2_parse:
>
> mpeg2dec->action = mpeg2_seek_header;
> switch (mpeg2dec->code) {
> case 0x00:
> show_msgbox("libmpeg2","case 0 mpeg2dec->code");
> return mpeg2dec->state;
> case 0xb3:
> case 0xb7:
> case 0xb8:
> show_msgbox("libmpeg2","case b8 mpeg2dec->code");
> return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
> default:
> mpeg2dec->action = seek_chunk;
> show_msgbox("libmpeg2","default mpeg2dec->code"); // This is where it returns
> return STATE_INVALID;
> }
>
> Does anyone have any ideas on what could be causing this? The code isn't very well documented and it's hard to follow.
>
> Cheers,
|