Since nobody posted a clean solution I'll post a nasty hack.

avformat_open_input() returns a AVFormatContext pointer.

Using private headers and whatever else it takes, the following function
will find the socket and bump the receive buffer size. Obviously will
break if ever the header files change in the future.




#define CHECK(X, Y) { if ((X)) { printf("error setting udp buffer size:
%s", Y); }}

setUDPReceiveBufferSize(AVFormatContext *s, int size) {
    RTSPState *rt = (RTSPState *)s->priv_data;
    CHECK(!rt, "AVFormatContext has no RTSPState pointer");
    for (int i = 0; i < rt->nb_rtsp_streams; i++) {
        RTSPStream *rtsp_st = rt->rtsp_streams[i];
        CHECK(!rtsp_st, "rtsp stream has null pointer");
        URLContext *rtp_urlc = rtsp_st->rtp_handle;
        CHECK(!rtp_urlc, "rtp url handle is null!");
        RTPContext *rtpc = (RTPContext *)rtp_urlc->priv_data;
        CHECK(!rtpc, "rtp context is null!");
        URLContext *udp_urlc = rtpc->rtp_hd;
        CHECK(!udp_urlc, "udp url handle is null!");
        UDPContext *udpc = (UDPContext *)udp_urlc->priv_data;
        CHECK(!udpc, "udp context is null!");
        CHECK(udpc->udp_fd < 0, "invalid udp file descriptor!");
        int ret = setsockopt(udpc->udp_fd, SOL_SOCKET, SO_RCVBUF, &size,
sizeof(size));
        CHECK(ret < 0, "failed to set buffer size options!");
   }
}

The private headers can be approximated like so:

typedef struct URLContext {
    void *av_class;
    void *prot;
    void *priv_data;
} URLContext;

typedef struct RTSPStream {
    URLContext *rtp_handle;
    void    *transport_priv;
    int        stream_index;
    int        interleaved_min, interleaved_max;
    char     control_url[1024];
    int     sdp_port;
    struct sockaddr_storage sdp_ip;
    int        sdp_ttl;
    int        sdp_payload_type;
    void    *dynamic_handler;
    void    *dynamic_protocol_context;
} RTSPStream;

typedef struct RTSPState {
    void *clazz;
    URLContext *rtsp_hd;
    int nb_rtsp_streams;
    struct RTSPStream **rtsp_streams;
} RTSPState;

typedef struct RTPContext {
    URLContext *rtp_hd, *rtcp_hd;
    int rtp_fd, rtcp_fd;
} RTPContext;

typedef struct {
    int udp_fd;
    int ttl;
    int buffer_size;
    int is_multicast;
    int local_port;
} UDPContext;




_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to