Hello.
This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Please send us by fax any message containing deadlines as incoming e-mails are not screened for response deadlines. The integrity and security of this message cannot be guaranteed on the Internet.
I am writing a program to get the value of each sample inside a frame which generates by the tone generator.
My expected result is continuous frame segments with data.
But in fact, for every frame that has data, then there is a blank frame. The result is intermittent sine lines, such as below:
https://imgur.com/cZ57OGl
How can I draw a continuous sine line? Please help.
Here is my source code:
But in fact, for every frame that has data, then there is a blank frame. The result is intermittent sine lines, such as below:
https://imgur.com/cZ57OGl
How can I draw a continuous sine line? Please help.
Here is my source code:
#include <pjlib.h>
#include <pjmedia.h>
#include <unistd.h>
#define SAMPLE_RATE 8000.0 //8kHz
#define SAMPLE_PER_FRAME 200
#define BITS_PER_SAMPLE 16
int size = 0;
static pj_status_t get_frame(pjmedia_port *port)
{
char errmsg[PJ_ERR_MSG_SIZE];
pj_status_t status;
while(1) {
pjmedia_frame *frame = (pjmedia_frame *) port->port_data.pdata;
status = pjmedia_port_get_frame(port, frame);
if (status != PJ_SUCCESS) {
pj_strerror(status, errmsg, sizeof(errmsg));
PJ_LOG(1, (__FILE__, "Status %d: %s\n", status, errmsg));
}
pj_int16_t *data = ""> for (int i = 0; i < frame->size; i++) {
printf("%d,%d\n", size, data[i]);
size++;
}
}
}
int main (int argc, char* argv[]) {
pj_caching_pool cp;
pj_pool_t *pool;
pjmedia_stream *stream = NULL;
pj_status_t status;
pjmedia_conf *conf = NULL;
pjmedia_endpt *med_endpt;
pj_caching_pool_init(&cp, NULL, 0);
pool = pj_pool_create(&cp.factory, "test_pj_stream", 8000, 8000, NULL);
status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
pjmedia_conf_create(pool, 3, SAMPLE_RATE, 1, SAMPLE_PER_FRAME,BITS_PER_SAMPLE, PJMEDIA_CONF_NO_DEVICE, &conf);
pjmedia_port *tone_port;
status = pjmedia_tonegen_create(pool, SAMPLE_RATE, 1, SAMPLE_PER_FRAME, BITS_PER_SAMPLE, 0, &tone_port);
pjmedia_tone_desc tones[1];
tones[0].freq1 = 425;
tones[0].freq2 = 0;
tones[0]._on_msec_ = 1000;
tones[0].off_msec = 0;
tones[0].volume = PJMEDIA_TONEGEN_VOLUME;
status = pjmedia_tonegen_play(tone_port, 1, tones, PJMEDIA_TONEGEN_LOOP );
int tone_slot;
pjmedia_conf_add_port(conf, pool, tone_port, NULL, &tone_slot);
//start worker thread
pj_thread_t *thread;
pjmedia_frame frame;
void *buf;
buf = pj_pool_alloc(pool, 2*SAMPLE_RATE);
frame.buf = buf;
tone_port->port_data.pdata = (void*) &frame;
pj_thread_create(pool, "app", (pj_thread_proc*)&get_frame, tone_port, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread);
pj_thread_sleep(100);
while (1) sleep (2);
return 0;
}
#include <pjmedia.h>
#include <unistd.h>
#define SAMPLE_RATE 8000.0 //8kHz
#define SAMPLE_PER_FRAME 200
#define BITS_PER_SAMPLE 16
int size = 0;
static pj_status_t get_frame(pjmedia_port *port)
{
char errmsg[PJ_ERR_MSG_SIZE];
pj_status_t status;
while(1) {
pjmedia_frame *frame = (pjmedia_frame *) port->port_data.pdata;
status = pjmedia_port_get_frame(port, frame);
if (status != PJ_SUCCESS) {
pj_strerror(status, errmsg, sizeof(errmsg));
PJ_LOG(1, (__FILE__, "Status %d: %s\n", status, errmsg));
}
pj_int16_t *data = ""> for (int i = 0; i < frame->size; i++) {
printf("%d,%d\n", size, data[i]);
size++;
}
}
}
int main (int argc, char* argv[]) {
pj_caching_pool cp;
pj_pool_t *pool;
pjmedia_stream *stream = NULL;
pj_status_t status;
pjmedia_conf *conf = NULL;
pjmedia_endpt *med_endpt;
pj_caching_pool_init(&cp, NULL, 0);
pool = pj_pool_create(&cp.factory, "test_pj_stream", 8000, 8000, NULL);
status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
pjmedia_conf_create(pool, 3, SAMPLE_RATE, 1, SAMPLE_PER_FRAME,BITS_PER_SAMPLE, PJMEDIA_CONF_NO_DEVICE, &conf);
pjmedia_port *tone_port;
status = pjmedia_tonegen_create(pool, SAMPLE_RATE, 1, SAMPLE_PER_FRAME, BITS_PER_SAMPLE, 0, &tone_port);
pjmedia_tone_desc tones[1];
tones[0].freq1 = 425;
tones[0].freq2 = 0;
tones[0]._on_msec_ = 1000;
tones[0].off_msec = 0;
tones[0].volume = PJMEDIA_TONEGEN_VOLUME;
status = pjmedia_tonegen_play(tone_port, 1, tones, PJMEDIA_TONEGEN_LOOP );
int tone_slot;
pjmedia_conf_add_port(conf, pool, tone_port, NULL, &tone_slot);
//start worker thread
pj_thread_t *thread;
pjmedia_frame frame;
void *buf;
buf = pj_pool_alloc(pool, 2*SAMPLE_RATE);
frame.buf = buf;
tone_port->port_data.pdata = (void*) &frame;
pj_thread_create(pool, "app", (pj_thread_proc*)&get_frame, tone_port, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread);
pj_thread_sleep(100);
while (1) sleep (2);
return 0;
}
Best Regards,
===============================================================
Quy Bui Danh (Mr.)
===============================================================
Quy Bui Danh (Mr.)
Technical Lead
Mobile .: (+84) 1655 516 695
Email .: quybd@xxxxxxxxxxxx
DICOM TECHNOLOGY COMPANY LIMITED LTD
Headquarter: 15th Floor, Center Building, 85th Vu Trong Phung, Thanh Xuan, Hanoi - Tel: +84 24 22213077
Branch Office: 7th Floor, GIC Tower, 207B Hoang Van Thu, Ward 8, Phu Nhuan District, Ho Chi Minh City - Tel: +84 28 22533501
Website: dicom.com.vn (Dicom SI) ; dicom.vn (Dicom IOT)
This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Please send us by fax any message containing deadlines as incoming e-mails are not screened for response deadlines. The integrity and security of this message cannot be guaranteed on the Internet.
_______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@xxxxxxxxxxxxxxx http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org