Browse Source

Use AV_RB* macros where appropriate.

patch by Ronald S. Bultje, rsbultje gmail com
thread: Re: [FFmpeg-devel] remove int readers
date: Sat, 23 Jun 2007 09:32:12 -0400

Originally committed as revision 9499 to svn://svn.ffmpeg.org/ffmpeg/trunk
tags/v0.5
Ronald S. Bultje Diego Biurrun 18 years ago
parent
commit
80fb82346e
6 changed files with 20 additions and 33 deletions
  1. +3
    -8
      libavformat/ffm.c
  2. +1
    -1
      libavformat/mp3.c
  3. +12
    -17
      libavformat/mpegts.c
  4. +1
    -4
      libavformat/oggparsetheora.c
  5. +1
    -1
      libavformat/rtp.c
  6. +2
    -2
      libavformat/rtsp.c

+ 3
- 8
libavformat/ffm.c View File

@@ -601,12 +601,12 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
ffm->read_state = READ_DATA; ffm->read_state = READ_DATA;
/* fall thru */ /* fall thru */
case READ_DATA: case READ_DATA:
size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4];
size = AV_RB24(ffm->header + 2);
if (!ffm_is_avail_data(s, size)) { if (!ffm_is_avail_data(s, size)) {
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }


duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
duration = AV_RB24(ffm->header + 5);


av_new_packet(pkt, size); av_new_packet(pkt, size);
pkt->stream_index = ffm->header[0]; pkt->stream_index = ffm->header[0];
@@ -714,15 +714,10 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
offset_t ffm_read_write_index(int fd) offset_t ffm_read_write_index(int fd)
{ {
uint8_t buf[8]; uint8_t buf[8];
offset_t pos;
int i;


lseek(fd, 8, SEEK_SET); lseek(fd, 8, SEEK_SET);
read(fd, buf, 8); read(fd, buf, 8);
pos = 0;
for(i=0;i<8;i++)
pos |= (int64_t)buf[i] << (56 - i * 8);
return pos;
return AV_RB64(buf);
} }


void ffm_write_write_index(int fd, offset_t pos) void ffm_write_write_index(int fd, offset_t pos)


+ 1
- 1
libavformat/mp3.c View File

@@ -407,7 +407,7 @@ static int mp3_read_probe(AVProbeData *p)
buf2 = buf; buf2 = buf;


for(frames = 0; buf2 < end; frames++) { for(frames = 0; buf2 < end; frames++) {
header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3];
header = AV_RB32(buf2);
fsize = ff_mpa_decode_header(&avctx, header, &sample_rate); fsize = ff_mpa_decode_header(&avctx, header, &sample_rate);
if(fsize < 0) if(fsize < 0)
break; break;


+ 12
- 17
libavformat/mpegts.c View File

@@ -170,7 +170,7 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,


/* compute section length if possible */ /* compute section length if possible */
if (tss->section_h_size == -1 && tss->section_index >= 3) { if (tss->section_h_size == -1 && tss->section_index >= 3) {
len = (((tss->section_buf[1] & 0xf) << 8) | tss->section_buf[2]) + 3;
len = (AV_RB16(tss->section_buf + 1) & 0xfff) + 3;
if (len > 4096) if (len > 4096)
return; return;
tss->section_h_size = len; tss->section_h_size = len;
@@ -324,7 +324,7 @@ static inline int get16(const uint8_t **pp, const uint8_t *p_end)
p = *pp; p = *pp;
if ((p + 1) >= p_end) if ((p + 1) >= p_end)
return -1; return -1;
c = (p[0] << 8) | p[1];
c = AV_RB16(p);
p += 2; p += 2;
*pp = p; *pp = p;
return c; return c;
@@ -694,14 +694,9 @@ static void mpegts_scan_sdt(MpegTSContext *ts)


static int64_t get_pts(const uint8_t *p) static int64_t get_pts(const uint8_t *p)
{ {
int64_t pts;
int val;

pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
val = (p[1] << 8) | p[2];
pts |= (int64_t)(val >> 1) << 15;
val = (p[3] << 8) | p[4];
pts |= (int64_t)(val >> 1);
int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
pts |= (AV_RB16(p + 1) >> 1) << 15;
pts |= AV_RB16(p + 3) >> 1;
return pts; return pts;
} }


@@ -751,7 +746,7 @@ static void mpegts_push_data(MpegTSFilter *filter,
new_pes_av_stream(pes, code); new_pes_av_stream(pes, code);
} }
pes->state = MPEGTS_PESHEADER_FILL; pes->state = MPEGTS_PESHEADER_FILL;
pes->total_size = (pes->header[4] << 8) | pes->header[5];
pes->total_size = AV_RB16(pes->header + 4);
/* NOTE: a zero total size means the PES size is /* NOTE: a zero total size means the PES size is
unbounded */ unbounded */
if (pes->total_size) if (pes->total_size)
@@ -928,7 +923,7 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet)
int len, pid, cc, cc_ok, afc, is_start; int len, pid, cc, cc_ok, afc, is_start;
const uint8_t *p, *p_end; const uint8_t *p, *p_end;


pid = ((packet[1] & 0x1f) << 8) | packet[2];
pid = AV_RB16(packet + 1) & 0x1fff;
is_start = packet[1] & 0x40; is_start = packet[1] & 0x40;
tss = ts->pids[pid]; tss = ts->pids[pid];
if (ts->auto_guess && tss == NULL && is_start) { if (ts->auto_guess && tss == NULL && is_start) {
@@ -1111,7 +1106,7 @@ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
return -1; return -1;
if (len < 6) if (len < 6)
return -1; return -1;
v = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
v = AV_RB32(p);
*ppcr_high = ((int64_t)v << 1) | (p[4] >> 7); *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7);
*ppcr_low = ((p[4] & 1) << 8) | p[5]; *ppcr_low = ((p[4] & 1) << 8) | p[5];
return 0; return 0;
@@ -1187,7 +1182,7 @@ static int mpegts_read_header(AVFormatContext *s,
ret = read_packet(&s->pb, packet, ts->raw_packet_size); ret = read_packet(&s->pb, packet, ts->raw_packet_size);
if (ret < 0) if (ret < 0)
return -1; return -1;
pid = ((packet[1] & 0x1f) << 8) | packet[2];
pid = AV_RB16(packet + 1) & 0x1fff;
if ((pcr_pid == -1 || pcr_pid == pid) && if ((pcr_pid == -1 || pcr_pid == pid) &&
parse_pcr(&pcr_h, &pcr_l, packet) == 0) { parse_pcr(&pcr_h, &pcr_l, packet) == 0) {
pcr_pid = pid; pcr_pid = pid;
@@ -1305,7 +1300,7 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
url_fseek(&s->pb, pos, SEEK_SET); url_fseek(&s->pb, pos, SEEK_SET);
if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
return AV_NOPTS_VALUE; return AV_NOPTS_VALUE;
if ((pcr_pid < 0 || (((buf[1] & 0x1f) << 8) | buf[2]) == pcr_pid) &&
if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
parse_pcr(&timestamp, &pcr_l, buf) == 0) { parse_pcr(&timestamp, &pcr_l, buf) == 0) {
break; break;
} }
@@ -1319,7 +1314,7 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
url_fseek(&s->pb, pos, SEEK_SET); url_fseek(&s->pb, pos, SEEK_SET);
if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
return AV_NOPTS_VALUE; return AV_NOPTS_VALUE;
if ((pcr_pid < 0 || (((buf[1] & 0x1f) << 8) | buf[2]) == pcr_pid) &&
if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
parse_pcr(&timestamp, &pcr_l, buf) == 0) { parse_pcr(&timestamp, &pcr_l, buf) == 0) {
break; break;
} }
@@ -1344,7 +1339,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in
url_fseek(&s->pb, pos, SEEK_SET); url_fseek(&s->pb, pos, SEEK_SET);
if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
return -1; return -1;
// pid = ((buf[1] & 0x1f) << 8) | buf[2];
// pid = AV_RB16(buf + 1) & 0x1fff;
if(buf[1] & 0x40) break; if(buf[1] & 0x40) break;
pos += ts->raw_packet_size; pos += ts->raw_packet_size;
} }


+ 1
- 4
libavformat/oggparsetheora.c View File

@@ -60,10 +60,7 @@ theora_header (AVFormatContext * s, int idx)


skip_bits(&gb, 7*8); /* 0x80"theora" */ skip_bits(&gb, 7*8); /* 0x80"theora" */


version = get_bits(&gb, 8) << 16;
version |= get_bits(&gb, 8) << 8;
version |= get_bits(&gb, 8);

version = get_bits_long(&gb, 24);
if (version < 0x030100) if (version < 0x030100)
{ {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,


+ 1
- 1
libavformat/rtp.c View File

@@ -603,7 +603,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
return -1; return -1;
} }
payload_type = buf[1] & 0x7f; payload_type = buf[1] & 0x7f;
seq = (buf[2] << 8) | buf[3];
seq = AV_RB16(buf + 2);
timestamp = AV_RB32(buf + 4); timestamp = AV_RB32(buf + 4);
ssrc = AV_RB32(buf + 8); ssrc = AV_RB32(buf + 8);
/* store the ssrc in the RTPDemuxContext */ /* store the ssrc in the RTPDemuxContext */


+ 2
- 2
libavformat/rtsp.c View File

@@ -720,7 +720,7 @@ static void rtsp_skip_packet(AVFormatContext *s)
ret = url_readbuf(rt->rtsp_hd, buf, 3); ret = url_readbuf(rt->rtsp_hd, buf, 3);
if (ret != 3) if (ret != 3)
return; return;
len = (buf[1] << 8) | buf[2];
len = AV_RB16(buf + 1);
#ifdef DEBUG #ifdef DEBUG
printf("skipping RTP packet len=%d\n", len); printf("skipping RTP packet len=%d\n", len);
#endif #endif
@@ -1098,7 +1098,7 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
if (ret != 3) if (ret != 3)
return -1; return -1;
id = buf[0]; id = buf[0];
len = (buf[1] << 8) | buf[2];
len = AV_RB16(buf + 1);
#ifdef DEBUG_RTP_TCP #ifdef DEBUG_RTP_TCP
printf("id=%d len=%d\n", id, len); printf("id=%d len=%d\n", id, len);
#endif #endif


Loading…
Cancel
Save