*/
#include "avformat.h"
#include "rm.h"
+#include "avstring.h"
-
-static void get_str(ByteIOContext *pb, char *buf, int buf_size)
+static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len)
{
- int len, i;
- char *q;
+ int i;
+ char *q, r;
- len = get_be16(pb);
q = buf;
for(i=0;i<len;i++) {
+ r = get_byte(pb);
if (i < buf_size - 1)
- *q++ = get_byte(pb);
+ *q++ = r;
}
- *q = '\0';
+ if (buf_size > 0) *q = '\0';
}
-static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
+static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
{
- int len, i;
- char *q;
+ get_strl(pb, buf, buf_size, get_be16(pb));
+}
- len = get_byte(pb);
- q = buf;
- for(i=0;i<len;i++) {
- if (i < buf_size - 1)
- *q++ = get_byte(pb);
- }
- *q = '\0';
+static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
+{
+ get_strl(pb, buf, buf_size, get_byte(pb));
}
static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
}
} else {
st->codec->codec_id = CODEC_ID_NONE;
- pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
- buf);
+ av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name));
}
if (read_all) {
get_byte(pb);
/* very old .ra format */
return rm_read_header_old(s, ap);
} else if (tag != MKTAG('.', 'R', 'M', 'F')) {
- return AVERROR_IO;
+ return AVERROR(EIO);
}
get_be32(pb); /* header size */
flags = get_be16(pb); /* flags */
break;
case MKTAG('C', 'O', 'N', 'T'):
- get_str(pb, s->title, sizeof(s->title));
- get_str(pb, s->author, sizeof(s->author));
- get_str(pb, s->copyright, sizeof(s->copyright));
- get_str(pb, s->comment, sizeof(s->comment));
+ get_str16(pb, s->title, sizeof(s->title));
+ get_str16(pb, s->author, sizeof(s->author));
+ get_str16(pb, s->copyright, sizeof(s->copyright));
+ get_str16(pb, s->comment, sizeof(s->comment));
break;
case MKTAG('M', 'D', 'P', 'R'):
st = av_new_stream(s, 0);
for(i=0;i<s->nb_streams;i++) {
av_free(s->streams[i]);
}
- return AVERROR_IO;
+ return AVERROR(EIO);
}
static int get_num(ByteIOContext *pb, int *len)
for (y = 0; y < rm->sub_packet_h; y++)
for (x = 0; x < rm->sub_packet_h/2; x++)
if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
- return AVERROR_IO;
+ return AVERROR(EIO);
rm->audio_stream_num = 0;
rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
// Release first audio packet
len= av_get_packet(pb, pkt, len);
pkt->stream_index = 0;
if (len <= 0) {
- return AVERROR_IO;
+ return AVERROR(EIO);
}
pkt->size = len;
}
resync:
len=sync(s, ×tamp, &flags, &i, &pos);
if(len<0)
- return AVERROR_IO;
+ return AVERROR(EIO);
st = s->streams[i];
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
rm->current_stream= st->id;
// av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
+ if((h & 0xc0) == 0x80)
+ len=pos;
if(len2 && len2<len)
len=len2;
rm->remaining_len-= len;
/* for AC3, needs to swap bytes */
if (st->codec->codec_id == CODEC_ID_AC3) {
ptr = pkt->data;
- for(j=0;j<len;j+=2) {
+ for(j=0;j<pkt->size;j+=2) {
FFSWAP(int, ptr[0], ptr[1]);
ptr += 2;
}