Пример #1
0
/*********************************************************
            Main Code
*********************************************************/
int main(void)
{
  ioinit();

  // Make sure all the pixels are working
  splash_screen();

  // Enable Global Interrupts
  sei();

  while (1) {
    if (PINB & (1 << CS)) { // If CS goes high, SPI com is complete.
      frame_index = 0; // Reset the frame index.
    }

    post_frames(); // Update display with current frame data.

    // Check to see if there is a new frame to parse.
    if (new_frame == 1) {
      parse_frame();
    }

    // Increment clicks to determine LED brightness levels.
    timer_ticks = (timer_ticks + 1) & 0x07; // Circular 0 to 7
  }

  return 0;
}
Пример #2
0
ID3V2::ID3V2(FXuchar *b,FXint len) : buffer(b),size(len),p(0),padstart(0),padend(0),length(-1) {
  const FXchar & flags = buffer[5];

  version = buffer[3];
  GM_DEBUG_PRINT("[id3v2] version %d\n",version);

  buffer+=10;
  size-=10;

  /// we can skip the footer
  if (version>=4 && flags&HAS_FOOTER)
    size-=10;

  /// Apply unsync, according to spec 2.3, the extended header also needs unsyncing
  if (flags&HAS_UNSYNC) {
    unsync(buffer,size);
    }

  /// skip the extended header
  if (version>=3 && flags&HAS_EXTENDED_HEADER) {
    FXint header_size;
    if (version==3)
      header_size = ID3_INT32(buffer);
    else
      header_size = ID3_SYNCSAFE_INT32(buffer);
    buffer+=header_size;
    }

  /// Parse
  p=0;
  while(p<size)
    parse_frame();
  }
Пример #3
0
ID3v2_tag* load_tag(const char* file_name)
{
    // Declaration
    FILE* file;
    ID3v2_tag* tag;
    ID3v2_frame_list* frame_list;
    ID3v2_header* tag_header;
    
    // Initialization
    tag = new_tag();
    tag_header = get_tag_header(file_name);
    
    if(tag_header == NULL || 
       get_tag_version(tag_header) == NO_COMPATIBLE_TAG)
    {
        // No compatible ID3 tag in the file, or we got some problem opening the file
        free_tag(tag);
        return NULL;
    }
    
    // Associations
    tag->tag_header = tag_header;
    file = fopen(file_name, "rb");
    if(file == NULL)
    {
        perror("Error opening file");
        free_tag(tag);
        return NULL;
    }
    
    tag->raw = (char*) malloc(tag->tag_header->tag_size * sizeof(char));
    fseek(file, 10, SEEK_SET);
    fread(tag->raw, tag->tag_header->tag_size, 1, file);
    fclose(file);
    
    int offset = 0;
    while(offset < tag->tag_header->tag_size)
    {
        ID3v2_frame* frame;
        frame = parse_frame(tag->raw, offset, get_tag_version(tag_header));

        if(frame != NULL)
        {
            offset += frame->size + 10;
            add_to_list(tag->frames, frame);
        }
        else
        {
            break;
        }
    }
    
    return tag;
}
Пример #4
0
Файл: parser.c Проект: rju/slp
/* Main parser function
 */
int parse() {
	token = yylex();
	do {
		switch (token) {
		case TITLE:
			if (!parse_title()) return 0;
			break;
		case AUTHOR:
			if (!parse_author()) return 0;
			break;
		case DATE:
			if (!parse_date()) return 0;
			break;
		case SECTION:
			if (!parse_section()) return 0;
			break;
		case FRAME:
			if (!parse_frame()) return 0;
			break;
		case PART:
			if (!parse_part()) return 0;
			break;
		case EOF:
		case ZERO:
			return 1;
		case NEWLINE:
			token = yylex();
			break;
		case IMAGE:
			fprintf(stderr, "[%d] Top mode: figure not allowed in top mode.\n",yylineno);
			return 0;
		case ANIMATION:
			fprintf(stderr, "[%d] Top mode: figure not allowed in top mode.\n",yylineno);
			return 0;
		case LISTING:
			fprintf(stderr, "[%d] Top mode: listing not allowed in top mode.\n", yylineno);
			return 0;
		case STRUCT:
			fprintf(stderr, "[%d] Top mode: structure not allowed in top mode.\n", yylineno);
			return 0;
		case ITEM:
			fprintf(stderr, "[%d] Top mode: item not allowed in top mode.\n", yylineno);
			return 0;
		default:
			fprintf(stderr, "[%d] Top mode: %s \"%s\" not allowed in top mode.\n", yylineno,
					get_token_name(token), yytext);
			return 0;
		}
	} while (token != EOF);

	return 1;
}
Пример #5
0
int do_stuff(can::bus* bus, logging_services::logger* log){
  char          buffer[128];
  unsigned int  can_id;
  int           success;

  success = bus->receive(128, buffer, &can_id); 

  if(success == -1){
    return 0;
  }/*if*/
  else{
    parse_frame(can_id, buffer, log);
    return 1;
  }/*else*/

}/*do_stuff*/
Пример #6
0
/* scans forward to the next aac frame and makes sure
 * the entire frame is in the buffer.
 */
static int buffer_fill_frame(struct aac_data *data)
{
	unsigned char *datap;
	int rc, n, len;
	int max = 32768;

	while (1) {
		/* need at least 6 bytes of data */
		rc = buffer_fill_min(data, 6);
		if (rc <= 0)
			break;

		len = buffer_length(data);
		datap = buffer_data(data);

		/* scan for a frame */
		for (n = 0; n < len - 5; n++) {
			/* give up after 32KB */
			if (max-- == 0) {
				logit ("no frame found!");
				/* FIXME: set errno? */
				return -1;
			}

			/* see if there's a frame at this location */
			rc = parse_frame(datap + n);
			if (rc == 0)
				continue;

			/* found a frame, consume all data up to the frame */
			buffer_consume (data, n);

			/* rc == frame length */
			rc = buffer_fill_min (data, rc);
			if (rc <= 0)
				goto end;

			return 1;
		}

		/* consume what we used */
		buffer_consume (data, n);
	}

end:
	return rc;
}
Пример #7
0
int main(int argc, char *argv[])
{
        if(0 != deal_with_parameter(argc, argv)) {
                return -1;
        }

        fd_i = fopen(file_i, "rb");
        if(NULL == fd_i) {
                RPTERR("open \"%s\" failed", file_i);
                return -1;
        }

        if(0 != parse_header()) {
                return -1;
        }

        parse_frame();

        fclose(fd_i);
        return 0;
}
Пример #8
0
/* Processes one tuple of the snapshot query result set. */
int snapshot_tuple(client_context_t context, PGresult *res, int row_number) {
    if (PQnfields(res) != 1) {
        client_error(context, "Unexpected response with %d fields", PQnfields(res));
        return EIO;
    }
    if (PQgetisnull(res, row_number, 0)) {
        client_error(context, "Unexpected null response value");
        return EIO;
    }
    if (PQfformat(res, 0) != 1) { /* format 1 == binary */
        client_error(context, "Unexpected response format: %d", PQfformat(res, 0));
        return EIO;
    }

    /* wal_pos == 0 == InvalidXLogRecPtr */
    int err = parse_frame(context->repl.frame_reader, 0, PQgetvalue(res, row_number, 0),
            PQgetlength(res, row_number, 0));
    if (err) {
        client_error(context, "Error parsing frame data: %s", avro_strerror());
    }
    return err;
}
Пример #9
0
/**
 * Loads a set of frames from a file into a model. Returns true on success.
 */
bool load_animation(model *mdl, int frames, FILE *fp)
{
  int i;
  anim *anim;
  char buffer[BUFF_LEN];

  if(!mdl || frames <= 0 || !fp)
    return false;


  /* Find the first empty animation inside the model and create a new
   * animations, assigning the spare slot to it. */
  for(i = 0 ; i < mdl->n_anims; i++)
  {
    if(mdl->anims[i] == NULL)
    {
      printf("Creating new animation, %d frames, %d bones\n", frames,
          mdl->n_bones);
      anim = new_anim(frames, mdl->n_bones);
      mdl->anims[i] = anim;
      break;
    }
    /* If no slots are avaliable then return false. */
    else if(i == mdl->n_anims - 1)
      return false;
  }

  /* Continue reading in files until all the frames have been read in. */
  i = 0;
  while(fgets(buffer, BUFF_LEN - 1, fp) != NULL) 
    if(parse_frame(anim, buffer, mdl->n_bones))
      if(++i == frames)
        break;

  if(i != frames)
    return false;

  return true;
}
Пример #10
0
static void indexer_dv_proc_frame(anim_index_builder *idx,
                                  unsigned char *buffer,
                                  int UNUSED(data_size),
                                  struct anim_index_entry *entry)
{
	int isPAL;
	
	indexer_dv_context *This = (indexer_dv_context *) idx->private_data;

	isPAL = (buffer[3] & 0x80);

	This->got_record_date = FALSE;
	This->got_record_time = FALSE;

	parse_frame(This, buffer, isPAL);
	proc_frame(This, buffer, isPAL);

	if (This->curr_frame >= 0) {
		write_index(This, entry);
		inc_frame(&This->curr_frame, &This->ref_time_read, isPAL);
	}
	else {
		This->backbuffer[This->fsize++] = *entry;
		if (This->fsize >= 31) {
			int i;

			fprintf(stderr, "indexer_dv::indexer_dv_proc_frame: "
			        "backbuffer overrun, emergency flush");

			for (i = 0; i < This->fsize; i++) {
				write_index(This, This->backbuffer + i);
			}
			This->fsize = 0;
		}
	}
}
Пример #11
0
static int parse(AVCodecParserContext *ctx,
                 AVCodecContext *avctx,
                 const uint8_t **out_data, int *out_size,
                 const uint8_t *data, int size)
{
    VP9ParseContext *s = ctx->priv_data;
    int full_size = size;
    int marker;

    if (size <= 0) {
        *out_size = 0;
        *out_data = data;

        return 0;
    }

    if (s->n_frames > 0) {
        *out_data = data;
        *out_size = s->size[--s->n_frames];
        parse_frame(ctx, *out_data, *out_size);

        return s->n_frames > 0 ? *out_size : size /* i.e. include idx tail */;
    }

    marker = data[size - 1];
    if ((marker & 0xe0) == 0xc0) {
        int nbytes = 1 + ((marker >> 3) & 0x3);
        int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;

        if (size >= idx_sz && data[size - idx_sz] == marker) {
            const uint8_t *idx = data + size + 1 - idx_sz;
            int first = 1;

            switch (nbytes) {
#define case_n(a, rd) \
            case a: \
                while (n_frames--) { \
                    unsigned sz = rd; \
                    idx += a; \
                    if (sz > size) { \
                        s->n_frames = 0; \
                        *out_size = size; \
                        *out_data = data; \
                        av_log(avctx, AV_LOG_ERROR, \
                               "Superframe packet size too big: %u > %d\n", \
                               sz, size); \
                        return full_size; \
                    } \
                    if (first) { \
                        first = 0; \
                        *out_data = data; \
                        *out_size = sz; \
                        s->n_frames = n_frames; \
                    } else { \
                        s->size[n_frames] = sz; \
                    } \
                    data += sz; \
                    size -= sz; \
                } \
                parse_frame(ctx, *out_data, *out_size); \
                return *out_size

                case_n(1, *idx);
                case_n(2, AV_RL16(idx));
                case_n(3, AV_RL24(idx));
                case_n(4, AV_RL32(idx));
            }
        }
    }
Пример #12
0
	void compile(const char* path, CompileOptions& opts)
	{
		Buffer buf = opts.read(path);
		JSONParser json(buf);
		JSONElement root = json.root();

		// Read width/height
		const float width  = root.key("width" ).to_float();
		const float height = root.key("height").to_float();
		const uint32_t num_frames = root.key("frames").size();

		Array<float> vertices(default_allocator());
		Array<uint16_t> indices(default_allocator());
		uint32_t num_idx = 0;
		for (uint32_t i = 0; i < num_frames; i++)
		{
			JSONElement e(root.key("frames")[i]);

			SpriteFrame frame;
			parse_frame(e, frame);

			const SpriteFrame& fd = frame;

			// Compute uv coords
			const float u0 = fd.region.x / width;
			const float v0 = fd.region.y / height;
			const float u1 = (fd.region.x + fd.region.z) / width;
			const float v1 = (fd.region.y + fd.region.w) / height;

			// Compute positions
			const float w = fd.region.z / CROWN_DEFAULT_PIXELS_PER_METER;
			const float h = fd.region.w / CROWN_DEFAULT_PIXELS_PER_METER;

			const float x0 = fd.scale.x * (-w * 0.5f) + fd.offset.x;
			const float y0 = fd.scale.y * (-h * 0.5f) + fd.offset.y;
			const float x1 = fd.scale.x * ( w * 0.5f) + fd.offset.x;
			const float y1 = fd.scale.y * ( h * 0.5f) + fd.offset.y;

			array::push_back(vertices, x0); array::push_back(vertices, y0); // position
			array::push_back(vertices, u0); array::push_back(vertices, v0); // uv

			array::push_back(vertices, x1); array::push_back(vertices, y0); // position
			array::push_back(vertices, u1); array::push_back(vertices, v0); // uv

			array::push_back(vertices, x1); array::push_back(vertices, y1); // position
			array::push_back(vertices, u1); array::push_back(vertices, v1); // uv

			array::push_back(vertices, x0); array::push_back(vertices, y1); // position
			array::push_back(vertices, u0); array::push_back(vertices, v1); // uv

			array::push_back(indices, uint16_t(num_idx)); array::push_back(indices, uint16_t(num_idx + 1)); array::push_back(indices, uint16_t(num_idx + 2));
			array::push_back(indices, uint16_t(num_idx)); array::push_back(indices, uint16_t(num_idx + 2)); array::push_back(indices, uint16_t(num_idx + 3));
			num_idx += 4;
		}

		const uint32_t num_vertices = array::size(vertices) / 4; // 4 components per vertex
		const uint32_t num_indices = array::size(indices);

		// Write header
		opts.write(SPRITE_VERSION);

		opts.write(num_vertices);
		for (uint32_t i = 0; i < array::size(vertices); i++)
		{
			opts.write(vertices[i]);
		}

		opts.write(num_indices);
		for (uint32_t i = 0; i < array::size(indices); i++)
		{
			opts.write(indices[i]);
		}
	}
Пример #13
0
int main(int argc, char* argv[]) {
    char c, *inFile;
    inFile = NULL;
    sc_frame_rect rect;
    
	#ifndef _WIN32
    signal(SIGPIPE, sig_pipe_handler);
	#endif

    while ((c = getopt (argc, argv, "w:h:u:r:f:")) != -1) {
        switch (c) {
            case 'w':
                rect.width = (uint16_t) atoi(optarg);
                break;
            case 'h':
                rect.height = (uint16_t) atoi(optarg);
                break;
            case 'u':
                streamUri = optarg;
                break;
            case 'r':
                roomName = optarg;
                break;
            case 'f':
                inFile = optarg;
                break;
        }
    }
    
    int fd;
    if(inFile) {
        printf("Started streamer with width: %i, height: %i, URI: %s, roomName: %s, File: %s\n", rect.width, rect.height, streamUri, roomName, inFile);
        fd = open(inFile, O_RDONLY);
    } else {
        printf("Started streamer with width: %i, height: %i, URI: %s, roomName: %s \n", rect.width, rect.height, streamUri, roomName);
        fd = fileno(stdin);
    }
    
    // main processing loop
    while(TRUE) {
        sc_bytestream_packet packet = sc_bytestream_get_event(fd);
        sc_mouse_coords coords;
        sc_frame frame;
        
        if(streamer.rtmp_setup == 1 && (!RTMP_IsConnected(streamer.rtmp) || RTMP_IsTimedout(streamer.rtmp))) {
            #ifdef _WIN32
				sc_streamer_die();
			#else
				sc_streamer_reconnect(&streamer);
			#endif
        }
        
        RTMPPacket rp = { 0 };
        if(streamer.rtmp_setup == 1  && streamer.so_name != NULL && streamer.have_inital_SO != 1 && RTMP_ReadPacket(streamer.rtmp, &rp)) {
            if (RTMPPacket_IsReady(&rp) && rp.m_packetType == RTMP_PACKET_TYPE_SHARED_OBJECT)
            {
                AVal SO_name;
                AMF_DecodeString(rp.m_body, &SO_name);
                
                streamer.so_version = AMF_DecodeInt32(rp.m_body+2+SO_name.av_len);
                streamer.have_inital_SO = 1;
            }
        }
        
        switch(packet.header.type) {
            case STARTVIDEO:
                capture_rect = rect;
                start_time_stamp = packet.header.timestamp;
                streamer = sc_streamer_init_video(streamUri, roomName, capture_rect, start_time_stamp);
                break;
            case STOPVIDEO:
				sc_streamer_stop_video(&streamer);
				sc_streamer_teardown_windows();
                exit(1);
                break;
            case STARTCURSOR:
                start_time_stamp = packet.header.timestamp;
				streamer = sc_streamer_init_cursor(streamUri, roomName, start_time_stamp);
                break;
            case STOPCURSOR:
				sc_streamer_stop_cursor(&streamer);
				sc_streamer_teardown_windows();
                exit(1);
                break;
            case MOUSE:
				coords = parse_mouse_coords(packet);
                streamer.so_version++;
                sc_streamer_send_mouse_data(&streamer, &coords, packet.header.timestamp);
                break;
            case VIDEO:
				frame = parse_frame(packet);

				if((RTMP_IsConnected(streamer.rtmp) &&  !RTMP_IsTimedout(streamer.rtmp)))
					sc_streamer_send_frame(&streamer, &frame, packet.header.timestamp);
				
				free(frame.framePtr);
				break;
            case NO_DATA:
            default:
                exit(0);
                break;    // maybe a wait is in order
        }
    }
    
    return 0;
}
Пример #14
0
int mp3_fileParse(MediaFile_t *media)
{
    int retcode = SUCCESS;

    TRACE_INFO(MP3, BLD_GREEN "mp3_fileParse()" CLR_RESET);

    // Init bitstream to parse container infos
    Bitstream_t *bitstr = init_bitstream(media, NULL);

    if (bitstr != NULL)
    {
        // Init a MediaStream_t to store samples
        retcode = init_bitstream_map(&media->tracks_audio[0], 0, 999999);

        // Init an MP3 structure
        mp3_t mp3;
        memset(&mp3, 0, sizeof(mp3_t));

        // A convenient way to stop the parser
        mp3.run = true;

        // stuff
        int64_t min_frame_size = 128;
        int64_t frame_offset = 0;
        uint32_t frame_header = 0;
        bool first_frame_parsed = false;

        // Loop on 1st level elements
        while (mp3.run == true &&
               retcode == SUCCESS &&
               bitstream_get_absolute_byte_offset(bitstr) < (media->file_size - min_frame_size))
        {
            // Seek to the next frame offset // Assume the MP3 frames will not be bigger than 4Gib
            uint32_t jump_bits = (uint32_t)(frame_offset - bitstream_get_absolute_byte_offset(bitstr)) * 8;
            if (jump_bits > 0)
                skip_bits(bitstr, jump_bits);

            // Read the next frame header
            frame_header = read_bits(bitstr, 32);

            // note: check frame header against 11 bits long instead of 12, to be compatible with MPEG-1/2/2.5
            if ((frame_header & 0xFFE00000) == 0xFFE00000)
            {
                TRACE_1(MP3, "> MP3 frame @ %lli", frame_offset);

                if (first_frame_parsed == false)
                {
                    frame_offset = parse_frame_full(bitstr, frame_header, &mp3, media);

                    if (frame_offset > 0)
                        first_frame_parsed = true;
                    else
                        retcode = FAILURE;
                }
                else
                {
                    frame_offset = parse_frame(bitstr, frame_header, &mp3, media);
                }
            }
            else if ((frame_header & 0xFFFFFF00) == 0x54414700)
            {
                TRACE_INFO(MP3, "> ID3v1 tag @ %lli", frame_offset);
                mp3.run = false;

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = media->file_size - frame_offset;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if ((frame_header & 0xFFFFFF00) == 0x49443300)
            {
                int id3tag_version = ((frame_header & 0x000000FF) << 8) + read_bits(bitstr, 8);
                /*int id3tag_flag =*/ read_bits(bitstr, 8);

                TRACE_INFO(MP3, "> ID3v2.%i @ %lli", id3tag_version, frame_offset);

                uint32_t id3tag_size = read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size += 10; // bytes already read

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = id3tag_size;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }

                // Simulate TAG parsing
                frame_offset += id3tag_size;
            }
            else if (frame_header == 0x4C595249)
            {
                TRACE_INFO(MP3, "> Lyrics3 tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x58696E67)
            {
                TRACE_INFO(MP3, "> XING tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x56425249)
            {
                TRACE_INFO(MP3, "> VBRI tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x41504554)
            {
                TRACE_WARNING(MP3, "> APE tag @ %lli", frame_offset);

                /*uint32_t apetag_header =*/ read_bits(bitstr, 32); // 0x41474558, second part of the tag header
                /*uint32_t apetag_version =*/ read_bits(bitstr, 32);
                uint32_t apetag_size = 8 + read_bits(bitstr, 32); //  APE header size (8 bytes) + tag content size

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = apetag_size;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }

                // Simulate TAG parsing
                frame_offset = frame_offset + apetag_size;
            }
            else
            {
                // Try to find a new startcode closeby...
                frame_offset += 1;
                TRACE_3(MP3, "Unknown frame header @ %lli (startcode: 0x%X)",
                        frame_offset, frame_header);
            }
        }

        if (retcode == SUCCESS)
        {
            retcode = mp3_indexer_track(media, &mp3);
            if (retcode == SUCCESS)
            {
                retcode = mp3_indexer(media, &mp3);
            }
        }
    }
    else
    {
        retcode = FAILURE;
    }

    return retcode;
}