[FFmpeg-soc] [soc]: r4484 - in rtmp: rtmpdec.c rtmppkt.c rtmppkt.h
kostya
subversion at mplayerhq.hu
Thu Jun 18 06:58:34 CEST 2009
Author: kostya
Date: Thu Jun 18 06:58:33 2009
New Revision: 4484
Log:
Use common chunk_size instead of one for each channel, and as a consequence,
get rid of RTMPPacketHistory since simple array of RTMPPacket is enough.
Modified:
rtmp/rtmpdec.c
rtmp/rtmppkt.c
rtmp/rtmppkt.h
Modified: rtmp/rtmpdec.c
==============================================================================
--- rtmp/rtmpdec.c Thu Jun 18 06:38:39 2009 (r4483)
+++ rtmp/rtmpdec.c Thu Jun 18 06:58:33 2009 (r4484)
@@ -45,7 +45,8 @@ typedef enum {
typedef struct RTMPState {
URLContext *rtmp_hd;
- RTMPPacketHistory rhist, whist;
+ RTMPPacket prev_pkt[2][RTMP_CHANNELS];
+ int chunk_size;
char playpath[256];
ClientState state;
int main_stream_id;
@@ -121,7 +122,7 @@ static void gen_connect(AVFormatContext
pkt.data_size = p - pkt.data;
- rtmp_packet_write(s, rt->rtmp_hd, &pkt, &rt->whist);
+ rtmp_packet_write(s, rt->rtmp_hd, &pkt, rt->chunk_size, rt->prev_pkt[1]);
}
static void gen_create_stream(AVFormatContext *s, RTMPState *rt)
@@ -139,7 +140,7 @@ static void gen_create_stream(AVFormatCo
rtmp_amf_write_tag(&p, AMF_NUMBER, &num);
rtmp_amf_write_tag(&p, AMF_NULL, NULL);
- rtmp_packet_write(s, rt->rtmp_hd, &pkt, &rt->whist);
+ rtmp_packet_write(s, rt->rtmp_hd, &pkt, rt->chunk_size, rt->prev_pkt[1]);
rtmp_packet_destroy(&pkt);
}
@@ -163,7 +164,7 @@ static void gen_play(AVFormatContext *s,
num = 0.0;
rtmp_amf_write_tag(&p, AMF_NUMBER, &num);
- rtmp_packet_write(s, rt->rtmp_hd, &pkt, &rt->whist);
+ rtmp_packet_write(s, rt->rtmp_hd, &pkt, rt->chunk_size, rt->prev_pkt[1]);
rtmp_packet_destroy(&pkt);
// set client buffer time disguised in ping packet
@@ -174,7 +175,7 @@ static void gen_play(AVFormatContext *s,
bytestream_put_be32(&p, 1);
bytestream_put_be32(&p, 256); //TODO: what is a good value here?
- rtmp_packet_write(s, rt->rtmp_hd, &pkt, &rt->whist);
+ rtmp_packet_write(s, rt->rtmp_hd, &pkt, rt->chunk_size, rt->prev_pkt[1]);
rtmp_packet_destroy(&pkt);
}
@@ -187,7 +188,7 @@ static void gen_pong(AVFormatContext *s,
p = pkt.data;
bytestream_put_be16(&p, 7);
bytestream_put_be32(&p, AV_RB32(ppkt->data+2) + 1);
- rtmp_packet_write(s, rt->rtmp_hd, &pkt, &rt->whist);
+ rtmp_packet_write(s, rt->rtmp_hd, &pkt, rt->chunk_size, rt->prev_pkt[1]);
rtmp_packet_destroy(&pkt);
}
@@ -339,15 +340,6 @@ static int rtmp_handshake(AVFormatContex
return 0;
}
-static void rtmp_init_hist(RTMPPacketHistory *hist)
-{
- int i;
-
- for (i = 0; i < RTMP_CHANNELS; i++) {
- hist->chunk_size[i] = (i == RTMP_AUDIO_CHANNEL) ? 64 : 128;
- }
-}
-
static int rtmp_probe(AVProbeData *p)
{
if (av_strstart(p->filename, "rtmp:", NULL))
@@ -367,8 +359,6 @@ static int rtmp_read_header(AVFormatCont
url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
path, sizeof(path), s->filename);
- rtmp_init_hist(&rt->rhist);
- rtmp_init_hist(&rt->whist);
if(port == -1)
port = RTMP_DEFAULT_PORT;
snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
@@ -377,6 +367,7 @@ static int rtmp_read_header(AVFormatCont
if (rtmp_handshake(s, rt))
return -1;
+ rt->chunk_size = 128;
rt->state = STATE_HANDSHAKED;
//extract "app" part from path
if (!strncmp(path, "/ondemand/", 10)) {
@@ -438,11 +429,7 @@ static int rtmp_parse_result(AVFormatCon
pkt->data_size);
return -1;
}
- t = AV_RB32(pkt->data);
- for (i = 0; i < RTMP_CHANNELS; i++) {
- rt->rhist.chunk_size[i] = t;
- rt->whist.chunk_size[i] = t;
- }
+ rt->chunk_size = AV_RB32(pkt->data);
break;
case RTMP_PT_PING:
t = AV_RB16(pkt->data);
@@ -490,7 +477,7 @@ static int rtmp_read_packet(AVFormatCont
while (url_ftell(&rt->pb) == rt->flv_size) {
RTMPPacket rpkt;
int has_data = 0;
- if ((ret = rtmp_packet_read(s, rt->rtmp_hd, &rpkt, &rt->rhist)) != 0) {
+ if ((ret = rtmp_packet_read(s, rt->rtmp_hd, &rpkt, rt->chunk_size, rt->prev_pkt[0])) != 0) {
if (ret > 0) {
nanosleep(&ts, NULL);
continue;
Modified: rtmp/rtmppkt.c
==============================================================================
--- rtmp/rtmppkt.c Thu Jun 18 06:38:39 2009 (r4483)
+++ rtmp/rtmppkt.c Thu Jun 18 06:58:33 2009 (r4484)
@@ -69,7 +69,7 @@ void rtmp_amf_write_tag(uint8_t **dst, A
}
int rtmp_packet_read(AVFormatContext *ctx, URLContext *h, RTMPPacket *p,
- RTMPPacketHistory *hist)
+ int chunk_size, RTMPPacket *prev_pkt)
{
uint8_t hdr, t, buf[16];
int stream_id, timestamp, data_size, offset = 0;
@@ -117,15 +117,15 @@ int rtmp_packet_read(AVFormatContext *ct
if (hdr == RTMP_PS_TWELVEBYTES)
p->extra = AV_RL32(buf);
while (data_size > 0) {
- int toread = FFMIN(data_size, hist->chunk_size[stream_id]);
+ int toread = FFMIN(data_size, chunk_size);
int r;
if ((r = url_read_complete(h, p->data + offset, toread)) != toread) {
av_log(ctx, AV_LOG_ERROR, "Need %d read %d\n", toread, r);
rtmp_packet_destroy(p);
return -1;
}
- data_size -= hist->chunk_size[stream_id];
- offset += hist->chunk_size[stream_id];
+ data_size -= chunk_size;
+ offset += chunk_size;
if (data_size > 0) {
url_read_complete(h, &t, 1); //marker
if (t != (0xC0 + stream_id)) {
@@ -138,11 +138,10 @@ int rtmp_packet_read(AVFormatContext *ct
}
int rtmp_packet_write(AVFormatContext *ctx, URLContext *h, RTMPPacket *pkt,
- RTMPPacketHistory *hist)
+ int chunk_size, RTMPPacket *prev_pkt)
{
uint8_t pkt_hdr[16], *p = pkt_hdr;
int mode = RTMP_PS_TWELVEBYTES;
- int chunk_size = hist->chunk_size[pkt->stream_id];
int off = 0;
if (pkt->type != RTMP_PT_INVOKE)
@@ -280,7 +279,9 @@ void rtmp_packet_inspect(AVFormatContext
default: av_log(NULL,0,"%X",pkt->type);
}
av_log(NULL,0," ts %d/%d size %d\n", pkt->timestamp, pkt->extra, pkt->data_size);
- if (pkt->type == RTMP_PT_INVOKE || pkt->type == RTMP_PT_NOTIFY
- || pkt->type == RTMP_PT_METADATA)
+ if (pkt->type == RTMP_PT_INVOKE || pkt->type == RTMP_PT_NOTIFY)
parse_amf(pkt->data, pkt->data_size);
+ if (pkt->type == RTMP_PT_VIDEO && pkt->data_size < 10){
+ int i;av_log(NULL,0,"Data:");for(i=0;i<pkt->data_size;i++)av_log(NULL,0," %02X",pkt->data[i]);av_log(NULL,0,"\n");
+ }
}
Modified: rtmp/rtmppkt.h
==============================================================================
--- rtmp/rtmppkt.h Thu Jun 18 06:38:39 2009 (r4483)
+++ rtmp/rtmppkt.h Thu Jun 18 06:58:33 2009 (r4484)
@@ -106,26 +106,16 @@ typedef struct RTMPPacket {
int data_size; ///< packet payload size
} RTMPPacket;
-/**
- * saved parameters for reading RTMP packets
- *
- * Since RTMP server may choose to send partial packet for some channel we need
- * to set missing parameters from the previous packet on the same channel.
- */
-typedef struct RTMPPacketHistory {
- RTMPPacket prev_pkt[RTMP_CHANNELS]; ///< previous read packet parameters
- int chunk_size[RTMP_CHANNELS]; ///< chunk size for each channel
-} RTMPPacketHistory;
-
-
int rtmp_packet_create(RTMPPacket *pkt, int stream_id, RTMPPacketType type,
int timestamp, int size);
void rtmp_packet_destroy(RTMPPacket *pkt);
-int rtmp_packet_read(AVFormatContext *ctx, URLContext *h, RTMPPacket *p, RTMPPacketHistory *hist);
+int rtmp_packet_read(AVFormatContext *ctx, URLContext *h, RTMPPacket *p,
+ int chunk_size, RTMPPacket *prev_pkt);
-int rtmp_packet_write(AVFormatContext *ctx, URLContext *h, RTMPPacket *p, RTMPPacketHistory *hist);
+int rtmp_packet_write(AVFormatContext *ctx, URLContext *h, RTMPPacket *p,
+ int chunk_size, RTMPPacket *prev_pkt);
int rtmp_amf_tag_size(int type, const void *data);
More information about the FFmpeg-soc
mailing list