rfc3984.h 3.32 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
aymeric's avatar
aymeric committed
18 19 20 21 22
*/

#ifndef rfc3984_h
#define rfc3984_h

Simon Morlat's avatar
Simon Morlat committed
23 24
#include <mediastreamer2/mscommon.h>
#include <mediastreamer2/msqueue.h>
25
#include <mediastreamer2/msfactory.h>
Simon Morlat's avatar
Simon Morlat committed
26 27 28 29 30
/*
This file declares an API useful to pack/unpack H264 nals as described in RFC3984
It is part of the public API to allow external H264 plugins use this api.
*/

aymeric's avatar
aymeric committed
31 32 33 34
#ifdef __cplusplus
extern "C"{
#endif

35 36 37
typedef enum{
	Rfc3984FrameAvailable = 1,
	Rfc3984FrameCorrupted = 1<<1,
38
	Rfc3984IsKeyFrame = 1<<2, /*set when a frame has SPS + PPS or IDR (possibly both)*/
39
	Rfc3984NewSPS = 1<<3,
40 41 42 43
	Rfc3984NewPPS = 1<<4,
	Rfc3984HasSPS = 1<<5,
	Rfc3984HasPPS = 1<<6,
	Rfc3984HasIDR = 1<<7,
44 45
}Rfc3984Status;
	
aymeric's avatar
aymeric committed
46 47 48 49
typedef struct Rfc3984Context{
	MSQueue q;
	mblk_t *m;
	int maxsz;
50 51
	unsigned int status; /*bitmask of Rfc3984Status values*/
	mblk_t *sps, *pps;
52
	mblk_t *last_sps, *last_pps;
aymeric's avatar
aymeric committed
53
	uint32_t last_ts;
54
	uint16_t ref_cseq;
aymeric's avatar
aymeric committed
55 56
	uint8_t mode;
	bool_t stap_a_allowed;
57
	bool_t initialized_ref_cseq;
aymeric's avatar
aymeric committed
58 59
} Rfc3984Context;

60 61 62
MS2_DEPRECATED MS2_PUBLIC Rfc3984Context *rfc3984_new(void);
MS2_PUBLIC Rfc3984Context *rfc3984_new_with_factory(MSFactory *factory);

Simon Morlat's avatar
Simon Morlat committed
63
MS2_PUBLIC void rfc3984_destroy(Rfc3984Context *ctx);
64

65
void rfc3984_init(Rfc3984Context *ctx);
aymeric's avatar
aymeric committed
66

Simon Morlat's avatar
Simon Morlat committed
67
MS2_PUBLIC void rfc3984_set_mode(Rfc3984Context *ctx, int mode);
aymeric's avatar
aymeric committed
68 69

/* some stupid phones don't decode STAP-A packets ...*/
Simon Morlat's avatar
Simon Morlat committed
70
MS2_PUBLIC void rfc3984_enable_stap_a(Rfc3984Context *ctx, bool_t yesno);
aymeric's avatar
aymeric committed
71 72

/*process NALUs and pack them into rtp payloads */
Simon Morlat's avatar
Simon Morlat committed
73
MS2_PUBLIC void rfc3984_pack(Rfc3984Context *ctx, MSQueue *naluq, MSQueue *rtpq, uint32_t ts);
aymeric's avatar
aymeric committed
74

75 76

MS2_PUBLIC void rfc3984_unpack_out_of_band_sps_pps(Rfc3984Context *ctx, mblk_t *sps, mblk_t *pps);
77 78
/**
 * Process incoming rtp data and output NALUs, whenever possible.
Simon Morlat's avatar
Simon Morlat committed
79 80
 * @return 0 if everything was ok, -1 on error (inconsistencies in sequence numbers for example).
 * @note the naluq output argument may be filled with incomplete data even if return value was -1.
81 82 83 84 85 86 87 88 89 90 91
 * @deprecated use rfc3984_unpack2
**/
MS2_DEPRECATED MS2_PUBLIC int rfc3984_unpack(Rfc3984Context *ctx, mblk_t *im, MSQueue *naluq);

/**
 * Process incoming rtp data and output NALUs, whenever possible.
 * @param ctx the Rfc3984Context object
 * @param im a new H264 packet to process
 * @param naluq a MSQueue into which a frame ready to be decoded will be output, in the form of a sequence of NAL units.
 * @return a bitmask of Rfc3984Status values.
 * The return value is a bitmask of the #Rfc3984Status enum.
92
**/
93
MS2_PUBLIC unsigned int rfc3984_unpack2(Rfc3984Context *ctx, mblk_t *im, MSQueue *naluq);
aymeric's avatar
aymeric committed
94 95 96 97 98 99 100 101 102

void rfc3984_uninit(Rfc3984Context *ctx);

#ifdef __cplusplus
}
#endif

#endif