+ else if (stream->type == PMT_CSO)\r
+ {\r
+ cso_struct *cso = stream->param;\r
+ int read_pos, read_len, out_offs, rret;\r
+ int block = cso->fpos_out >> 11;\r
+ int index = cso->index[block];\r
+ int index_end = cso->index[block+1];\r
+ unsigned char *out = ptr, *tmp_dst;\r
+\r
+ ret = 0;\r
+ while (bytes != 0)\r
+ {\r
+ out_offs = cso->fpos_out&0x7ff;\r
+ if (out_offs == 0 && bytes >= 2048)\r
+ tmp_dst = out;\r
+ else tmp_dst = cso->out_buff;\r
+\r
+ read_pos = (index&0x7fffffff) << cso->header.align;\r
+\r
+ if (index < 0) {\r
+ if (read_pos != cso->fpos_in)\r
+ fseek(stream->file, read_pos, SEEK_SET);\r
+ rret = fread(tmp_dst, 1, 2048, stream->file);\r
+ cso->fpos_in = read_pos + rret;\r
+ if (rret != 2048) break;\r
+ } else {\r
+ read_len = (((index_end&0x7fffffff) << cso->header.align) - read_pos) & 0xfff;\r
+ if (block != cso->block_in_buff)\r
+ {\r
+ if (read_pos != cso->fpos_in)\r
+ fseek(stream->file, read_pos, SEEK_SET);\r
+ rret = fread(cso->in_buff, 1, read_len, stream->file);\r
+ cso->fpos_in = read_pos + rret;\r
+ if (rret != read_len) {\r
+ elprintf(EL_STATUS, "cso: read failed @ %08x", read_pos);\r
+ break;\r
+ }\r
+ cso->block_in_buff = block;\r
+ }\r
+ rret = uncompress2(tmp_dst, 2048, cso->in_buff, read_len);\r
+ if (rret != 0) {\r
+ elprintf(EL_STATUS, "cso: uncompress failed @ %08x with %i", read_pos, rret);\r
+ break;\r
+ }\r
+ }\r
+\r
+ rret = 2048;\r
+ if (out_offs != 0 || bytes < 2048) {\r
+ //elprintf(EL_STATUS, "cso: unaligned/nonfull @ %08x, offs=%i, len=%u", cso->fpos_out, out_offs, bytes);\r
+ if (bytes < rret) rret = bytes;\r
+ if (2048 - out_offs < rret) rret = 2048 - out_offs;\r
+ memcpy(out, tmp_dst + out_offs, rret);\r
+ }\r
+ ret += rret;\r
+ out += rret;\r
+ cso->fpos_out += rret;\r
+ bytes -= rret;\r
+ block++;\r
+ index = index_end;\r
+ index_end = cso->index[block+1];\r
+ }\r
+ }\r