Skip to content

Commit

Permalink
init rtsp mp4-file-source/ffmpeg-file-source member
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Aug 28, 2022
1 parent 33a24fd commit 9a7c815
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 47 deletions.
8 changes: 4 additions & 4 deletions libmov/test/mov-file-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int mov_file_cache_read(void* fp, void* data, uint64_t bytes)
else
{
file->off = 0;
file->len = fread(file->ptr, 1, (int)sizeof(file->ptr), file->fp);
file->len = (unsigned int)fread(file->ptr, 1, sizeof(file->ptr), file->fp);
if (file->len < 1)
return 0 != ferror(file->fp) ? ferror(file->fp) : -1 /*EOF*/;
}
Expand All @@ -71,7 +71,7 @@ static int mov_file_cache_read(void* fp, void* data, uint64_t bytes)
if (file->off < file->len)
{
unsigned int n = file->len - file->off;
n = n > bytes ? bytes : n;
n = n > bytes ? (unsigned int)bytes : n;
memcpy(p, file->ptr + file->off, n);
file->tell += n;
file->off += n;
Expand All @@ -92,7 +92,7 @@ static int mov_file_cache_write(void* fp, const void* data, uint64_t bytes)
if (file->off + bytes < sizeof(file->ptr))
{
memcpy(file->ptr + file->off, data, bytes);
file->off += bytes;
file->off += (unsigned int)bytes;
return 0;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ static int mov_file_cache_seek(void* fp, int64_t offset)
static int64_t mov_file_cache_tell(void* fp)
{
struct mov_file_cache_t* file = (struct mov_file_cache_t*)fp;
if (ftell64(file->fp) != file->tell + (int)(file->len - file->off))
if (ftell64(file->fp) != (int64_t)(file->tell + (uint64_t)(int)(file->len - file->off)))
return -1;
return (int64_t)file->tell;
//return ftell64(file->fp);
Expand Down
9 changes: 5 additions & 4 deletions librtsp/source/sdp/sdp-aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

// RFC6416 RTP Payload Format for MPEG-4 Audio/Visual Streams
int sdp_aac_latm(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int sample_rate, int channel_count, const void* extra, int extra_size)
Expand Down Expand Up @@ -50,7 +51,7 @@ int sdp_aac_latm(uint8_t *data, int bytes, const char* proto, unsigned short por
payload, mpeg4_aac_profile_level(&aac), aac.profile);

if (n + r * 2 + 1 > bytes)
return -1; // don't have enough memory
return -ENOMEM; // don't have enough memory
n += (int)base16_encode((char*)data + n, config, r);

if (n < bytes)
Expand Down Expand Up @@ -88,7 +89,7 @@ int sdp_aac_generic(uint8_t *data, int bytes, const char* proto, unsigned short
n = snprintf((char*)data, bytes, pattern, port, proto && *proto ? proto : "RTP/AVP", payload, payload, sample_rate, channel_count, payload, mpeg4_aac_profile_level(&aac));

if (n + extra_size * 2 + 1 > bytes)
return -1; // don't have enough memory
return -ENOMEM; // don't have enough memory

// For MPEG-4 Audio streams, config is the audio object type specific
// decoder configuration data AudioSpecificConfig()
Expand All @@ -108,7 +109,7 @@ int sdp_aac_latm_load(uint8_t* data, int bytes, const char* config)

n = (int)strlen(config);
if (n / 2 > sizeof(buf))
return -1;
return -E2BIG;

n = (int)base16_decode(buf, config, n);
n = mpeg4_aac_stream_mux_config_load(buf, n, &aac);
Expand All @@ -121,7 +122,7 @@ int sdp_aac_mpeg4_load(uint8_t* data, int bytes, const char* config)
int n;
n = (int)strlen(config);
if (n / 2 > bytes)
return -1;
return -E2BIG;

return (int)base16_decode(data, config, n);
}
Expand Down
11 changes: 6 additions & 5 deletions librtsp/source/sdp/sdp-fmtp-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

/// @return >0-ok, other-error
int mpeg4_avc_from_fmtp(struct mpeg4_avc_t* avc, const struct sdp_a_fmtp_h264_t* fmtp)
Expand All @@ -19,7 +20,7 @@ int mpeg4_avc_from_fmtp(struct mpeg4_avc_t* avc, const struct sdp_a_fmtp_h264_t*
memset(avc, 0, sizeof(*avc));
avc->nalu = 4;
if (3 != sscanf(fmtp->profile_level_id, "%2hhx%2hhx%2hhx", &avc->profile, &avc->compatibility, &avc->level))
return -1;
return -EINVAL;

off = 0;
p = fmtp->sprop_parameter_sets;
Expand All @@ -28,7 +29,7 @@ int mpeg4_avc_from_fmtp(struct mpeg4_avc_t* avc, const struct sdp_a_fmtp_h264_t*
next = strchr(p, ',');
n = next ? (int)(next - p) : (int)strlen(p);
if (off + (n + 3) / 4 * 3 > sizeof(avc->data))
return -1; // don't have enough space
return -ENOMEM; // don't have enough space

n = (int)base64_decode(avc->data + off, p, n);
t = avc->data[off] & 0x1f;
Expand Down Expand Up @@ -81,7 +82,7 @@ int mpeg4_hevc_from_fmtp(struct mpeg4_hevc_t* hevc, const struct sdp_a_fmtp_h265
next = strchr(p, ',');
n = next ? (int)(next - p) : (int)strlen(p);
if (off + (n + 3) / 4 * 3 > sizeof(hevc->data))
return -1; // don't have enough space
return -ENOMEM; // don't have enough space

n = (int)base64_decode(hevc->data + off, p, n);
hevc->nalu[hevc->numOfArrays].data = hevc->data + off;
Expand All @@ -105,7 +106,7 @@ int aac_from_sdp_latm_config(struct mpeg4_aac_t* aac, struct sdp_a_fmtp_mpeg4_t*

n = (int)strlen(fmtp->config);
if (n / 2 > sizeof(buf))
return -1;
return -E2BIG;

n = (int)base16_decode(buf, fmtp->config, n);
return mpeg4_aac_stream_mux_config_load(buf, n, aac);
Expand All @@ -119,7 +120,7 @@ int aac_from_sdp_mpeg4_config(struct mpeg4_aac_t* aac, struct sdp_a_fmtp_mpeg4_t

n = (int)strlen(fmtp->config);
if ((n + 3) / 4 * 3 > sizeof(buf))
return -1;
return -E2BIG;

n = (int)base64_decode(buf, fmtp->config, n);
return mpeg4_aac_audio_specific_config_load(buf, n, aac);
Expand Down
7 changes: 4 additions & 3 deletions librtsp/source/sdp/sdp-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

int sdp_h264(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
{
Expand All @@ -31,7 +32,7 @@ int sdp_h264(uint8_t *data, int bytes, const char* proto, unsigned short port, i
for (i = 0; i < avc.nb_sps; i++)
{
if (n + 1 + avc.sps[i].bytes * 2 > bytes)
return -1; // // don't have enough memory
return -ENOMEM; // // don't have enough memory

if (i > 0 && n < bytes) data[n++] = ',';
n += (int)base64_encode((char*)data + n, avc.sps[i].data, avc.sps[i].bytes);
Expand All @@ -40,7 +41,7 @@ int sdp_h264(uint8_t *data, int bytes, const char* proto, unsigned short port, i
for (i = 0; i < avc.nb_pps; i++)
{
if (n + 1 + avc.sps[i].bytes * 2 > bytes)
return -1; // // don't have enough memory
return -ENOMEM; // // don't have enough memory

if (n < bytes) data[n++] = ',';
n += (int)base64_encode((char*)data + n, avc.pps[i].data, avc.pps[i].bytes);
Expand All @@ -64,7 +65,7 @@ int sdp_h264_load(uint8_t* data, int bytes, const char* config)
next = strchr(p, ',');
len = next ? (int)(next - p) : (int)strlen(p);
if (off + (len + 3) / 4 * 3 + (int)sizeof(startcode) > bytes)
return -1; // don't have enough space
return -ENOMEM; // don't have enough space

memcpy(data + off, startcode, sizeof(startcode));
n = (int)base64_decode(data + off + sizeof(startcode), p, len);
Expand Down
5 changes: 3 additions & 2 deletions librtsp/source/sdp/sdp-h265.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

int sdp_h265(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
{
Expand Down Expand Up @@ -42,7 +43,7 @@ int sdp_h265(uint8_t *data, int bytes, const char* proto, unsigned short port, i
continue;

if (n + 1 + hevc.nalu[j].bytes * 2 > bytes)
return -1; // don't have enough memory
return -ENOMEM; // don't have enough memory

if (k++ > 0 && n < bytes) data[n++] = ',';
n += (int)base64_encode((char*)data + n, hevc.nalu[j].data, hevc.nalu[j].bytes);
Expand Down Expand Up @@ -74,7 +75,7 @@ int sdp_h265_load(uint8_t* data, int bytes, const char* vps, const char* sps, co
next = strchr(p, ',');
len = next ? (int)(next - p) : (int)strlen(p);
if (off + (len + 3) / 4 * 3 + (int)sizeof(startcode) > bytes)
return -1; // don't have enough space
return -ENOMEM; // don't have enough space

memcpy(data + off, startcode, sizeof(startcode));
n = (int)base64_decode(data + off + sizeof(startcode), p, len);
Expand Down
3 changes: 2 additions & 1 deletion librtsp/source/sdp/sdp-mpeg4.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

int sdp_mpeg4_es(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
{
Expand All @@ -23,7 +24,7 @@ int sdp_mpeg4_es(uint8_t *data, int bytes, const char* proto, unsigned short por
n = snprintf((char*)data, bytes, pattern, port, proto && *proto ? proto : "RTP/AVP", payload, payload, payload);

if (n + extra_size * 2 + 1 > bytes)
return -1; // // don't have enough memory
return -ENOMEM; // // don't have enough memory

// It is a hexadecimal representation of an octet string that
// expresses the MPEG-4 Visual configuration information
Expand Down
5 changes: 3 additions & 2 deletions librtsp/source/sdp/sdp-payload.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sdp-payload.h"
#include "rtp-profile.h"
#include <assert.h>
#include <errno.h>

int sdp_payload_video(uint8_t* data, int bytes, int rtp, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
{
Expand Down Expand Up @@ -33,7 +34,7 @@ int sdp_payload_video(uint8_t* data, int bytes, int rtp, const char* proto, unsi

default:
assert(0);
return -1;
return -EPROTONOSUPPORT;
}
}

Expand All @@ -58,6 +59,6 @@ int sdp_payload_audio(uint8_t* data, int bytes, int rtp, const char* proto, unsi

default:
assert(0);
return -1;
return -EPROTONOSUPPORT;
}
}
6 changes: 3 additions & 3 deletions librtsp/source/server/aio/rtsp-server-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int rtsp_transport_tcp_create(socket_t socket, const struct sockaddr* addr, sock
rtsphandler.send = rtsp_session_send;

session = (struct rtsp_session_t*)calloc(1, sizeof(*session));
if (!session) return -1;
if (!session) return -ENOMEM;

session->socket = socket;
socket_addr_to(addr, addrlen, ip, &port);
Expand All @@ -160,7 +160,7 @@ int rtsp_transport_tcp_create(socket_t socket, const struct sockaddr* addr, sock
if (!session->rtsp || !session->aio)
{
rtsp_session_ondestroy(session);
return -1;
return -ENOMEM;
}

session->rtp.param = param;
Expand All @@ -169,7 +169,7 @@ int rtsp_transport_tcp_create(socket_t socket, const struct sockaddr* addr, sock
if (0 != aio_transport_recv(session->aio, session->buffer, sizeof(session->buffer)))
{
rtsp_session_ondestroy(session);
return -1;
return -ENOTCONN;
}

return 0;
Expand Down
12 changes: 6 additions & 6 deletions librtsp/source/utils/rtp-sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ int rtp_sender_init_video(struct rtp_sender_t* s, const char* proto, unsigned sh
if (avp < 0)
{
assert(0);
return -1;
return -EPROTONOSUPPORT;
}

r = sdp_payload_video(s->buffer, sizeof(s->buffer), s_payloads[avp].payload, proto, port, payload, s->frequency, extra, (int)bytes);
if (r < 0)
{
assert(0);
return -1;
return -EPROTONOSUPPORT;
}

s->encoder = rtp_payload_encode_create(payload, s->encoding, s->seq, s->ssrc, &handler, s);
Expand All @@ -88,7 +88,7 @@ int rtp_sender_init_video(struct rtp_sender_t* s, const char* proto, unsigned sh
if (r < 0 || r >= sizeof(s->buffer) || !s->rtp || !s->encoder)
{
rtp_sender_destroy(s);
return -1;
return -ENOMEM;
}
return r;
}
Expand Down Expand Up @@ -117,14 +117,14 @@ int rtp_sender_init_audio(struct rtp_sender_t* s, const char* proto, unsigned sh
if (avp < 0)
{
assert(0);
return -1;
return -EPROTONOSUPPORT;
}

r = sdp_payload_audio(s->buffer, sizeof(s->buffer), s_payloads[avp].payload, proto, port, payload, sample_rate, channel_count, extra, (int)bytes);
if (r < 0)
{
assert(0);
return -1;
return -EPROTONOSUPPORT;
}

switch(s_payloads[avp].payload)
Expand Down Expand Up @@ -158,7 +158,7 @@ int rtp_sender_init_audio(struct rtp_sender_t* s, const char* proto, unsigned sh
if (r < 0 || !s->rtp || !s->encoder)
{
rtp_sender_destroy(s);
return -1;
return -ENOMEM;
}
return r;
}
Expand Down
12 changes: 6 additions & 6 deletions librtsp/source/utils/rtsp-demuxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int rtsp_demuxer_mpeg2_fetch_stream(struct rtp_payload_info_t* pt, int pi

mpeg2 = avpayload_find_by_mpeg2((uint8_t)codecid);
if (mpeg2 < 0)
return -1;
return -EPROTONOSUPPORT;

for (i = 0; i < sizeof(pt->tracks) / sizeof(pt->tracks[0]); i++)
{
Expand All @@ -122,7 +122,7 @@ static int rtsp_demuxer_mpeg2_fetch_stream(struct rtp_payload_info_t* pt, int pi
}

if (i >= sizeof(pt->tracks) / sizeof(pt->tracks[0]))
return -1;
return -E2BIG;

if(pt->tracks[i].codec != s_payloads[mpeg2].codecid && pt->tracks[i].bs && pt->tracks[i].filter)
pt->tracks[i].bs->destroy(&pt->tracks[i].filter);
Expand Down Expand Up @@ -395,7 +395,7 @@ int rtsp_demuxer_add_payload(struct rtsp_demuxer_t* demuxer, int frequency, int
int (*onpacket)(void* param, const void* data, int bytes, uint32_t timestamp, int flags);

if (demuxer->count >= sizeof(demuxer->pt) / sizeof(demuxer->pt[0]))
return -1; // too many payload type
return -E2BIG; // too many payload type

avp = avpayload_find_by_rtp((uint8_t)payload, encoding);
// fixme: ffmpeg g711u sample rate 0
Expand Down Expand Up @@ -480,7 +480,7 @@ int rtsp_demuxer_add_payload(struct rtsp_demuxer_t* demuxer, int frequency, int
if (!pt->rtp || (pt->bs && !pt->filter))
{
rtsp_demuxer_payload_close(pt);
return -1;
return -ENOMEM;
}

demuxer->count++;
Expand Down Expand Up @@ -520,7 +520,7 @@ int rtsp_demuxer_rtpinfo(struct rtsp_demuxer_t* demuxer, uint16_t seq, uint32_t
if (demuxer->idx >= demuxer->count || demuxer->idx < 0)
{
assert(0);
return -1;
return -ENOENT;
}

pt = &demuxer->pt[demuxer->idx];
Expand Down Expand Up @@ -568,7 +568,7 @@ int rtsp_demuxer_rtcp(struct rtsp_demuxer_t* demuxer, void* buf, int len)
if (demuxer->idx >= demuxer->count || demuxer->idx < 0)
{
assert(0);
return -1;
return -ENOENT;
}

return rtp_demuxer_rtcp(demuxer->pt[demuxer->idx].rtp, buf, len);
Expand Down
Loading

0 comments on commit 9a7c815

Please sign in to comment.