资源简介
从ffmpeg库中提取出来的组播发送和接收代码,经过测试可以使用。
代码片段和文件信息
/**
* @file
* UDP protocol
*/
#define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */
/*
#include “avformat.h“
#include “avio_internal.h“
#include “libavutil/parseutils.h“
#include “libavutil/fifo.h“
#include “libavutil/intreadwrite.h“
#include “libavutil/avstring.h“
#include “libavutil/opt.h“
#include “libavutil/log.h“
#include “libavutil/time.h“
#include “internal.h“
#include “os_support.h“
#include “url.h“
*/
#include
#include
#include
#include
#include
#include
#include “udp.h“
#include
#define AVIO_FLAG_READ 1 /**< read-only */
#define AVIO_FLAG_WRITE 2 /**< write-only */
#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) /**< read-write pseudo flag */
/**
* Use non-blocking mode.
* If this flag is set operations on the context will return
* AVERROR(EAGAIN) if they can not be performed immediately.
* If this flag is not set operations on the context will never return
* AVERROR(EAGAIN).
* Note that this flag does not affect the opening/connecting of the
* context. Connecting a protocol will always block if necessary (e.g. on
* network protocols) but never hang (e.g. on busy devices).
* Warning: non-blocking protocols is work-in-progress; this flag may be
* silently ignored.
*/
#define AVIO_FLAG_NONBLOCK 8
/**
* Use direct mode.
* avio_read and avio_write should if possible be satisfied directly
* instead of going through a buffer and avio_seek will always
* call the underlying seek function directly.
*/
#define AVIO_FLAG_DIRECT 0x8000
#ifndef HAVE_PTHREAD_CANCEL
#define HAVE_PTHREAD_CANCEL 0
#endif
#ifndef IPV6_ADD_MEMBERSHIP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
#endif
/* error handling */
#if EDOM > 0
#define AVERROR(e) (-(e)) ///< Returns a negative error code from a POSIX error code to return from library functions.
#define AVUNERROR(e) (-(e)) ///< Returns a POSIX error code from a library function error return value.
#else
/* Some platforms have E* and errno already negated. */
#define AVERROR(e) (e)
#define AVUNERROR(e) (e)
#endif
#include
static int ff_network_wait_fd(int fd int write)
{
int ev = write ? POLLOUT : POLLIN;
struct pollfd p = { .fd = fd .events = ev .revents = 0 };
int ret;
ret = poll(&p 1 100);
return ret;
//return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN);
}
//poll 返回 =0 代表超时
//poll 返回 >0 代表有ret个套接字有数据可以处理
//poll 返回 <0 代表出错
//RETURN VALUE
// On success a positive number is returned; this is the number of structures which have non-zero revents fields
// (in other words those descriptors with events or errors reported). A value of 0 indicates that the call timed
// out and no file descriptors were ready. On error -1 is returned and errno is set ap
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5513 2015-12-01 13:21 udp.h
文件 29117 2015-12-02 17:16 udp.c
评论
共有 条评论