Skip to content

Commit

Permalink
Add function to initialize MediaFormat audio & video (#3925)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming authored Apr 17, 2024
1 parent 72d885d commit c5bc3d1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
6 changes: 1 addition & 5 deletions pjsip-apps/src/samples/pjsua2_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ void MyCall::onCallMediaState(OnCallMediaStateParam &prm)
med_port = new MyAudioMediaPort();

MediaFormatAudio fmt;
fmt.type = PJMEDIA_TYPE_AUDIO;
fmt.clockRate = 16000;
fmt.channelCount = 1;
fmt.bitsPerSample = 16;
fmt.frameTimeUsec = 20000;
fmt.init(PJMEDIA_FORMAT_PCM, 16000, 1, 20000, 16);

med_port->createPort("med_port", fmt);

Expand Down
34 changes: 30 additions & 4 deletions pjsip/include/pjsua2/media.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ struct MediaFormatAudio : public MediaFormat
MediaFormatAudio() : clockRate(0), channelCount(0), frameTimeUsec(0),
bitsPerSample(0), avgBps(0), maxBps(0)
{}

/**
* Initialization
*/
void init(pj_uint32_t formatId, unsigned clockRate, unsigned channelCount,
int frameTimeUsec, int bitsPerSample,
pj_uint32_t avgBps=0, pj_uint32_t maxBps=0);
};

/**
Expand All @@ -119,6 +126,21 @@ struct MediaFormatVideo : public MediaFormat
* Export to pjmedia_format.
*/
pjmedia_format toPj() const;

public:
/**
* Default constructor
*/
MediaFormatVideo() : width(0), height(0), fpsNum(0),
fpsDenum(1), avgBps(0), maxBps(0)
{}

/**
* Initialization
*/
void init(pj_uint32_t formatId, unsigned width, unsigned height,
int fpsNum, int fpsDenum=1,
pj_uint32_t avgBps=0, pj_uint32_t maxBps=0);
};

/** Array of MediaFormatAudio */
Expand Down Expand Up @@ -2026,12 +2048,16 @@ struct VideoPreviewOpParam {
unsigned windowFlags;

/**
* Media format video. If left uninitialized, this parameter will not be used and
* the capture device will be opened using PJMEDIA wrapper default format,
* e.g:
* Media format video. By default, this parameter is uninitialized
* and will not be used.
*
* To initialize it, use MediaFormatVideo::init().
* If left uninitialized, the capture device will be opened using
* PJMEDIA wrapper default format, e.g:
* - Android : PJMEDIA_FORMAT_I420 using the first supported size and 15fps
* - iOS : PJMEDIA_FORMAT_BGRA using size 352x288 and 15fps
* Note that when the preview is already opened, this setting will be ignored.
* Note that when the preview is already opened, this setting will be
* ignored.
*/
MediaFormatVideo format;

Expand Down
37 changes: 37 additions & 0 deletions pjsip/src/pjsua2/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ pjmedia_format MediaFormatAudio::toPj() const
return pj_format;
}

void MediaFormatAudio::init(pj_uint32_t formatId,
unsigned clockRate, unsigned channelCount,
int frameTimeUsec, int bitsPerSample,
pj_uint32_t avgBps, pj_uint32_t maxBps)
{
type = PJMEDIA_TYPE_AUDIO;
id = formatId;

this->clockRate = clockRate;
this->channelCount = channelCount;
this->frameTimeUsec = frameTimeUsec;
this->bitsPerSample = bitsPerSample;
this->avgBps = avgBps;
this->maxBps = maxBps;
}

///////////////////////////////////////////////////////////////////////////////
/* Audio Media operations. */
void ConfPortInfo::fromPj(const pjsua_conf_port_info &port_info)
Expand Down Expand Up @@ -1559,6 +1575,27 @@ pjmedia_format MediaFormatVideo::toPj() const
return pj_format;
}

void MediaFormatVideo::init(pj_uint32_t formatId,
unsigned width, unsigned height,
int fpsNum, int fpsDenum,
pj_uint32_t avgBps, pj_uint32_t maxBps)
{
#if PJSUA_HAS_VIDEO
type = PJMEDIA_TYPE_VIDEO;
id = formatId;

this->width = width;
this->height = height;
this->fpsNum = fpsNum;
this->fpsDenum = fpsDenum;
this->avgBps = avgBps;
this->maxBps = maxBps;
#else
type = PJMEDIA_TYPE_UNKNOWN;
#endif
}


///////////////////////////////////////////////////////////////////////////////
void VideoDevInfo::fromPj(const pjmedia_vid_dev_info &dev_info)
{
Expand Down

0 comments on commit c5bc3d1

Please sign in to comment.