You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bluesky-commits@incubator.apache.org by tp...@apache.org on 2008/06/04 02:48:20 UTC
svn commit: r662948 [23/31] - in /incubator/bluesky/NCstu-2.0: ./
autom4te.cache/ include/ intl/ po/ src/ src/.deps/ src/ffmpeg/ src/pic/
Added: incubator/bluesky/NCstu-2.0/src/client_communicate.cc
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/client_communicate.cc?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/client_communicate.cc (added)
+++ incubator/bluesky/NCstu-2.0/src/client_communicate.cc Tue Jun 3 19:48:16 2008
@@ -0,0 +1,614 @@
+#include "client_communicate.h"
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+#include <string.h>
+#include <stdlib.h>
+#include "callbacks.hh"
+#include "interface.hh"
+#include "errormessage.h"
+
+//#include "en_de_screen.h"
+#include "en_de_video.h"
+#include "en_de_audio.h"
+#include "en_de_screen.h"
+
+#include <gdk/gdkx.h>
+
+
+extern GtkWidget *chatview;
+extern GtkWidget *chat_show;
+ //extern GtkObject *adj1,*adj2;
+extern GtkWidget *clist1;
+extern DWORD TeacherMode;
+extern DWORD chatMode;
+extern DWORD Focus_student;
+extern client_ts_communicate client_comm;
+extern int loadflag;
+extern int addclassflag;
+extern GtkWidget *chatview;
+extern GtkWidget *stu_clist;
+extern GtkWidget *class1;
+extern GtkWidget *addclass;//å å
¥è¯¾å èå项
+extern GtkWidget *exitclass;//éåºè¯¾å èå项
+extern GtkWidget *addclasstool; // å å
¥è¯¾å å·¥å
·æ¡
+extern GtkWidget *exitclasstool;//éåºè¯¾å å·¥å
·æ¡
+extern GtkWidget *exchangetool;
+extern GtkWidget *cancelextool;
+//MCU connect with TServer
+extern GtkWidget *chat_show;
+extern GtkWidget *screenimage;
+extern GtkWidget *teachimage;
+
+extern GtkWidget *sendchatbut;
+extern GtkWidget *chatentry;
+
+extern GtkWidget *requestchange; //ç³è¯·ç¦ç¹èå项
+extern GtkWidget *cancelchange;
+
+//int y_position_adj1,height;
+//int y_position_adj2;
+//æ·»å æå¸çè§é³é¢æ¥æ¶
+extern CScreenReceiver g_teacher_screenreceiver;
+extern CVideoReceiver g_teacher_videoreceiver;
+extern CAudioReceiver g_teacher_audioreceiver;
+
+extern CV4LStuVideoSender g_student_videosender;
+extern CStuAudioSender g_student_audiosender;
+
+extern CVideoReceiver g_student_videoreceiver;
+
+extern CAudioReceiver g_student_audioreceiver;
+
+extern struct TRCClientLogin stulogin; //å¦çç»å½çåå§ä¿¡æ¯
+
+extern GtkTextBuffer *chat_buffer; //é对chatModeçtextviewè¿è¡æä½
+extern GtkTextIter chat_end;
+extern GtkTextIter chat_start;
+extern GtkTextBuffer *TeachChat_buffer; //é对chatModeçtextviewè¿è¡æä½
+extern GtkTextIter TeachChat_end;
+extern GtkTextIter TeachChat_start;
+
+ extern GtkWidget *networktool;
+ extern GtkWidget *networkconfig;
+
+extern GtkWidget *loadsys;//ç»å½ç³»ç»çèå
+extern GtkWidget *loadtool; // å å
¥ç³»ç»å·¥å
·æ¡
+
+ char *studentInfo[3];
+ int clientcount;
+
+extern int error_info_no;
+
+client_ts_communicate::client_ts_communicate()
+{
+ // may do something about MCU_Group
+ textview_mutex.Init();
+}
+
+client_ts_communicate::~client_ts_communicate()
+{
+
+}
+
+int client_ts_communicate::close_socket(int nHow)
+{
+ if(client_socket.ShutDown(nHow)==false)
+ {
+ perror("close socket error!");
+ return -1;
+ }
+
+ return 0;
+}
+
+int client_ts_communicate::establish_connect(LPCTSTR ts_IP,UINT ts_Port,UINT nSocketPort) //å¨MCUä¸å»ºç«socket线ç¨
+{
+ if( client_socket.Create(nSocketPort)!=true)
+ {
+ printf("Create socket failed!/n");
+ return -1;
+ }
+
+ if( client_socket.Connect(ts_IP,ts_Port)!=true)
+ {
+ perror("connet error!");
+ return -1;
+ }
+
+ client_socket_thread.Attach(&client_socket);
+
+ if( client_socket_thread.Init()!=true)
+ {
+ printf("Fail to initilize thread!/n");
+ return -1;
+ }
+ client_socket_thread.Start();
+
+ return 0;
+
+ //CAsyncSocketEx.connect(/**/);
+}
+
+int client_ts_communicate::send_mes(CRCLMSG mes,int mes_length) //å课å æå¡ä¸å¿åéæ¶æ¯
+{
+ //CAsyncSocketEx.send(/**/);
+
+ if( client_socket.Send(&mes,mes_length)==-1 )
+ {
+// perror("Send failed!");
+ return -1;
+ }
+ return 0;
+}
+
+
+int client_ts_communicate::recevie_msg(char *buf,int buf_length ) //æ¥æ¶è¯¾å æå¡ä¸å¿æ¶æ¯å¹¶å¤ç
+{
+ CRCLMSG * receive_str;
+ receive_str=(CRCLMSG *) buf;
+
+ printf("message ID is %d\n",receive_str->rclType);
+
+ switch(receive_str->rclType)
+ {
+ case 5021: //ç»å½æ¶æ¯çè¿åä¿¡æ¯
+ TRCClientLoginR *loginReceive; //å¦çç»å½çæ¶æ¯æ ¼å¼
+ loginReceive=(TRCClientLoginR *)receive_str->msg;
+
+ if(loginReceive->ResponseType==0) //ç»å½æå
+ {
+ loadflag=1;
+ Rec_ClientID=loginReceive->ClientID;
+ gtk_widget_set_sensitive (networktool, FALSE); //ç»å½èåç¶æ
+ gtk_widget_set_sensitive (networkconfig, FALSE); //ç»å½èåç¶æ
+ gtk_widget_set_sensitive (loadsys, FALSE); //ç»å½èåç¶æ
+ gtk_widget_set_sensitive (loadtool, FALSE); //ç»å½èåç¶æ
+ gtk_widget_set_sensitive (addclass,TRUE); //å å
¥è¯¾å çèå项
+ gtk_widget_set_sensitive (addclasstool,TRUE); //å å
¥è¯¾å çèå项
+ }
+
+
+ if(loginReceive->ResponseType==2) //该ç¨æ·åå·²å¨çº¿
+ error_info_no=1;
+
+ if(loginReceive->ResponseType==4) //ç»éé误ï¼ç½ç»åºç°æ
é
+ error_info_no=2;
+
+ if(loginReceive->ResponseType==6) //å¬è¯¾ç«¯äººæ°å·²æ»¡
+ error_info_no=3;
+
+ break;
+
+ case 10051: //ååºå®¢æ·ç«¯è¯·æ±è·åå½åç»ä¿¡æ¯æ¶æ¯
+ int index;
+ static char *classInfo[5];
+ static char tmp[10];
+ GetGroupInfoR=(TRCClientGetGroupInfoR *)receive_str->msg;
+ if(GetGroupInfoR->ResponseType==0)
+ {
+ gtk_clist_clear(GTK_CLIST(clist1)); //æ¸
é¤ææç课å å表
+ chatMode=GetGroupInfoR-> groupchatMode;
+ if(chatMode==0)
+ {
+ gtk_widget_set_sensitive (sendchatbut, FALSE); //课å èååå§ä¸ºæ æç¶æ
+ gtk_widget_set_sensitive (chatentry, FALSE); //课å èååå§ä¸ºæ æç¶æ
+ }
+ for(index=0;index<GetGroupInfoR->GroupCount;index++)
+ {
+ sprintf(tmp, "%d",GetGroupInfoR->GroupList[index].GroupID );
+ classInfo[0]=tmp;
+ classInfo[3]="";
+ classInfo[4]="";
+ classInfo[1]=GetGroupInfoR->GroupList[index].GroupName;
+ classInfo[2]=GetGroupInfoR->GroupList[index].TeacherName;
+
+ gtk_clist_freeze (GTK_CLIST(clist1));
+ gtk_clist_append(GTK_CLIST(clist1), classInfo); //æ·»å 课å ä¿¡æ¯
+ gtk_clist_thaw (GTK_CLIST(clist1));
+ }
+ }
+ if(GetGroupInfoR->ResponseType==60) //客æ·è·å¾è¯¾å å表失败
+ {
+ error_info_no=4;
+ }
+ break;
+
+ case 10021: //ååºå¦ç端å å
¥ç»ä¿¡æ¯
+ CRCLClientJoinInGroupR *JoinInGroupR ;
+ JoinInGroupR=(CRCLClientJoinInGroupR *)receive_str->msg;
+ printf("MCU's IP is %s\n",JoinInGroupR->MCUIP);
+ if(JoinInGroupR->ResponseType==0)
+ {
+ addclassflag=1; //å å
¥ç»æå
+ TeacherMode=JoinInGroupR->RoomMode;
+
+ gtk_widget_set_sensitive (exitclass,TRUE); //éåºè¯¾å çèå项
+ gtk_widget_set_sensitive (exitclasstool,TRUE); //éåºè¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (addclass,FALSE); //å å
¥è¯¾å çèå项设为å
+ gtk_widget_set_sensitive (addclasstool,FALSE); //å å
¥è¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (exchangetool,TRUE); //exchange_opçå·¥å
·æ¡
+ gtk_widget_set_sensitive (cancelextool,TRUE); //exchange_opçå·¥å
·æ¡
+ gtk_widget_set_sensitive (cancelchange,TRUE); //exchange_opçèå项
+ gtk_widget_set_sensitive (requestchange,TRUE); //exchange_opçèå项
+ gtk_widget_set_sensitive (loadsys,FALSE); //loadsysçèå项
+ gtk_widget_set_sensitive (loadtool,FALSE); //loadtoolçå·¥å
·æ¡
+
+ client_mcu_info.GroupID=JoinInGroupR->GroupID;
+ strcpy(client_mcu_info.MCUIP,JoinInGroupR->MCUIP);
+ strcpy(client_mcu_info.SeMCUIP,JoinInGroupR->SeMCUIP);
+ client_mcu_info.TAPort=JoinInGroupR->TAPort;
+ client_mcu_info.TVPort=JoinInGroupR->TVPort;
+ client_mcu_info.TSPort=JoinInGroupR->TSPort;
+ client_mcu_info.CAPort=JoinInGroupR->CAPort;
+ client_mcu_info.CVPort=JoinInGroupR->CVPort;
+ client_mcu_info.RoomMode=JoinInGroupR->RoomMode;
+
+ g_student_audioreceiver.Init();
+ g_student_audioreceiver.Start(stulogin.SeMCU_SAPort);
+
+ if(TeacherMode==1)
+ {
+ g_teacher_screenreceiver.Init();
+ g_teacher_screenreceiver.CreateXImage(GDK_WINDOW_XID(teachimage->window), 240, 76, 782, 580);
+ g_teacher_screenreceiver.Start(stulogin.SeMCU_TSPort);
+
+ }
+ g_teacher_videoreceiver.Init();
+ g_teacher_videoreceiver.CreateXImage(GDK_WINDOW_XID(teachimage->window), 2, 76, 320-90, 240-43);
+ g_teacher_videoreceiver.Start(stulogin.SeMCU_TVPort);
+ g_teacher_audioreceiver.Init();
+ g_teacher_audioreceiver.Start(stulogin.SeMCU_TAPort);
+
+ }
+ else if(JoinInGroupR->ResponseType==20) //å¦çå å
¥ç»å¤±è´¥
+ error_info_no=5;
+
+ else if(JoinInGroupR->ResponseType==22) //ç»å
人æ°å·²æ»¡
+ error_info_no=6;
+
+ break;
+
+ case 10031: //ååºå¦ç端离å¼ç»æ¶æ¯
+ TRCClientLeaveGroupR *LeaveGroupR;
+ LeaveGroupR=(TRCClientLeaveGroupR *)receive_str->msg;
+ if(LeaveGroupR->ResponseType==0)
+ {
+ addclassflag=0;
+
+ g_teacher_screenreceiver.Stop();
+ g_teacher_screenreceiver.CloseXImage();
+ g_teacher_videoreceiver.Stop();
+ g_teacher_videoreceiver.CloseXImage();
+ g_teacher_audioreceiver.Stop();
+
+ g_student_videosender.Stop();
+ g_student_videosender.CloseXImage();
+ g_student_audiosender.Pause();
+ g_student_videoreceiver.Stop();
+ g_student_videoreceiver.CloseXImage();
+
+ gtk_widget_set_sensitive (addclass,TRUE); //å å
¥è¯¾å çèå项
+ gtk_widget_set_sensitive (addclasstool,TRUE); //å å
¥è¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (exitclass,FALSE); //éåºè¯¾å çèå项
+ gtk_widget_set_sensitive (exitclasstool,FALSE); //éåºè¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (cancelchange,FALSE); //exchange_opçèå项
+ gtk_widget_set_sensitive (exchangetool,FALSE); //exchange_opçå·¥å
·æ¡
+ gtk_widget_set_sensitive (requestchange,FALSE); //exchange_opçèå项
+ gtk_widget_set_sensitive (cancelextool,FALSE); //exchange_opçå·¥å
·æ¡
+ }
+ else if(LeaveGroupR->ResponseType==21) //å¦ç离å¼ç»å¤±è´¥
+ error_info_no=7;
+ break;
+
+ case 1011: //ååºç¦ç¹å¦ççç³è¯·
+ TCRCLClientApplyFocusR *ApplyFocusR;
+ ApplyFocusR=(TCRCLClientApplyFocusR *)receive_str->msg;
+ if(GetGroupInfoR->ResponseType==40) //å·²æç¦ç¹
+ error_info_no=8;
+ else if(GetGroupInfoR->ResponseType==41) //ç³è¯·ç¦ç¹å¤±è´¥ï¼æªç¥
+ error_info_no=9;
+
+ break;
+
+ case 1021: //ååºå¦ç端主å¨æ¤éç¦ç¹æä½
+ TCRCLClientDestroyFocusR *DestroyFocusR;
+ DestroyFocusR=(TCRCLClientDestroyFocusR *)receive_str->msg;
+ if(DestroyFocusR->ResponseType==0)
+ {
+ Focus_student=0;
+ printf("The student destroy focus\n");
+ }
+ else if(DestroyFocusR->ResponseType==42) //æ¤éç¦ç¹å¤±è´¥
+ {
+ error_info_no=10;
+ }
+
+
+ break;
+
+ case 1052: //å¦ç端ååºæ为ç¦ç¹å¦ç
+ TCRCLTeacherAllowClientFocusRToMS *AllowClientFocusR;
+ AllowClientFocusR=(TCRCLTeacherAllowClientFocusRToMS *)receive_str->msg;
+ {
+ Focus_student=1;
+ unsigned long intIP2 = inet_addr(client_mcu_info.MCUIP);
+ intIP2 = ntohl(intIP2); //put in host byte order
+ RTPIPv4Address rtpAddr1(intIP2, client_mcu_info.CAPort);
+ RTPIPv4Address rtpAddr2(intIP2, client_mcu_info.CVPort);
+
+ //init video sender.
+ g_student_audioreceiver.Stop();
+
+ if(!g_student_videosender.IsInitialized()){
+ g_student_videosender.Init(6102);
+ }
+
+ g_student_videosender.SetMode(CV4LStuVideoSender::ModeTransmit);
+ printf("\n g_student_videosender.AddDestination(rtpAddr2):problem!!!!!!!!!!!\n");
+ g_student_videosender.ClearDestinations();
+ g_student_videosender.AddDestination(rtpAddr2);
+ g_student_videosender.Start();
+
+ //init audio sender.
+ g_student_audiosender.Init(6004);
+ g_student_audiosender.ClearDestinations();
+ g_student_audiosender.AddDestination(rtpAddr1);
+ g_student_audiosender.Start();
+ g_student_audiosender.Resume();
+ }
+ break;
+
+ case 1062: //å¦ç端æ¶å°æ课端åæ¶ç¦ç¹äºä»¶
+ TCRCLTeacherCancelClientFocusRToMS *TeacherCancelClientR;
+ TeacherCancelClientR=(TCRCLTeacherCancelClientFocusRToMS *)receive_str->msg;
+ Focus_student=0;
+ printf("cancel image OKKKKKKKKKKK\n");
+ g_student_audioreceiver.Init();
+ g_student_audioreceiver.Start(stulogin.SeMCU_SAPort);
+
+ g_student_videosender.Stop();
+ g_student_videosender.CloseXImage();
+ g_student_audiosender.Pause();
+ g_student_videoreceiver.Stop();
+ g_student_videoreceiver.CloseXImage();
+ break;
+
+ case 1031: //ååºææ¬äº¤äºä¸å
¶ä»å®¢æ·çä¿¡æ¯
+
+ char Text[1024]; //æåææ¬æ¶æ¯
+ TCRCLClientTextBroadcastR *TextBroadcastR;
+ TextBroadcastR=(TCRCLClientTextBroadcastR *)receive_str->msg;
+ strcpy(Text,TextBroadcastR->ClientName);
+ strcat(Text,":");
+ strcat(Text,TextBroadcastR->Info);
+ strcat(Text,"\n");
+ get_text_from_msg(Text);
+ flush_scrollar();
+ /* if(TeacherMode==1)
+ {
+ gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chatview),&TeachChat_end,&y_position_adj1,&height);
+ gtk_adjustment_set_value (GTK_ADJUSTMENT (adj1), y_position_adj1);
+ gtk_text_buffer_insert(TeachChat_buffer,&TeachChat_end,Text,-1);
+ }
+ else if(TeacherMode==0)
+ {
+ gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chat_show),&chat_end,&y_position_adj2,&height);
+ gtk_adjustment_set_value (GTK_ADJUSTMENT (adj2), y_position_adj2);
+ gtk_text_buffer_insert(chat_buffer,&chat_end,Text,-1);
+ }
+ */
+ break;
+
+ /*case 1041: //å¾å°å¦çå表
+
+ //static char *studentInfo[3];
+ static char avmode[500];
+ static char no_avmode[60];
+ TCRCLClientGetClientInfoR *GetClientInfoR;
+ GetClientInfoR=(TCRCLClientGetClientInfoR *)receive_str->msg;
+ strcpy(avmode,"True");
+ strcpy(no_avmode,"False");
+ if(GetClientInfoR->ResponseType==0)
+ {
+ printf("I get client %d\n",GetClientInfoR->ClientCount);
+ // gtk_clist_clear(GTK_CLIST(stu_clist)); //æ¸
é¤ææçå¦çå表
+ //sleep(1);
+ for(index=0;index<GetClientInfoR->ClientCount;index++)
+ {
+ printf("get STUID %d\n",GetClientInfoR->ClientList[index].ClientID);
+ printf(" student name is %s ,AVMOde is %d\n",GetClientInfoR->ClientList[index].ClientN,GetClientInfoR->ClientList[index].AVMode);
+ sprintf(tmp, "%d",GetClientInfoR->ClientList[index].ClientID);
+ studentInfo[0]=tmp;
+ // printf("student Info ID is %s",studentInfo[10][0]);
+ studentInfo[1]=GetClientInfoR->ClientList[index].ClientN;
+
+ if(GetClientInfoR->ClientList[index].AVMode==0)
+ studentInfo[2]=avmode;
+
+ else if(GetClientInfoR->ClientList[index].AVMode==1)
+ studentInfo[2]=no_avmode;
+ // append_list();
+ gtk_clist_freeze (GTK_CLIST(stu_clist));
+ gtk_clist_append(GTK_CLIST(stu_clist), studentInfo); //æ·»å å¨çº¿å¦çä¿¡æ¯
+ gtk_clist_thaw (GTK_CLIST(stu_clist));
+
+ }
+ }
+
+ break;
+ */
+
+ case 1081: //模å¼åæ¢
+
+ TCRCLTeacherSwitchModeR *TeacherSwitchMode;
+ TeacherSwitchMode=(TCRCLTeacherSwitchModeR *)receive_str->msg;
+ if(TeacherSwitchMode->ModeType==0)
+ {
+ //printf("The mode don't send screen\n");
+ g_teacher_screenreceiver.Stop();
+ g_teacher_screenreceiver.CloseXImage();
+ TeacherMode=0;
+ chatMode=1;
+ gtk_widget_set_sensitive (sendchatbut, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ gtk_widget_set_sensitive (chatentry, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ }
+ if(TeacherSwitchMode->ModeType==1)
+ {
+ TeacherMode=1;
+ chatMode=1;
+ gtk_widget_set_sensitive (sendchatbut, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ gtk_widget_set_sensitive (chatentry, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ g_teacher_screenreceiver.Init();
+ g_teacher_screenreceiver.CreateXImage(GDK_WINDOW_XID(teachimage->window), 240, 76, 782, 580);
+ g_teacher_screenreceiver.Start(stulogin.SeMCU_TSPort);
+ }
+
+ break;
+
+ case 10012: //åæ¶äº¤äºæ¨¡å¼
+
+ TRCDestoryGroupRToClient *DestoryGroupRToClient;
+ DestoryGroupRToClient=(TRCDestoryGroupRToClient *)receive_str->msg;
+ addclassflag=0;
+
+ g_teacher_screenreceiver.Stop();
+ g_teacher_screenreceiver.CloseXImage();
+ g_teacher_videoreceiver.Stop();
+ g_teacher_videoreceiver.CloseXImage();
+ g_teacher_audioreceiver.Stop();
+ g_student_videosender.Stop();
+ g_student_videosender.CloseXImage();
+ g_student_audiosender.Pause();
+ g_student_videoreceiver.Stop();
+ g_student_videoreceiver.CloseXImage();
+
+ gtk_widget_set_sensitive (addclass,TRUE); //å å
¥è¯¾å çèå项设为å
+ gtk_widget_set_sensitive (addclasstool,TRUE); //å å
¥è¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (exitclass,FALSE); //éåºè¯¾å çèå项
+ gtk_widget_set_sensitive (exitclasstool,FALSE); //éåºè¯¾å çå·¥å
·æ¡
+ gtk_widget_set_sensitive (cancelchange,FALSE); //exchange_opçå·¥å
·æ¡
+ gtk_widget_set_sensitive (exchangetool,FALSE); //exchangetoolçå·¥å
·æ¡
+ gtk_widget_set_sensitive (requestchange,FALSE); //requestchangeçèå项
+ gtk_widget_set_sensitive (cancelextool,FALSE); //cancelextoolçå·¥å
·æ¡
+
+ break;
+
+ case 1092: //æå¸ç«¯åæè天模å¼
+
+ TCRCLTeacherAgreeChat *TeacherAgreeChat;
+ TeacherAgreeChat=(TCRCLTeacherAgreeChat *)receive_str->msg;
+ if( TeacherAgreeChat->Agreechat==0)
+ {
+ chatMode=0;
+ gtk_widget_set_sensitive (sendchatbut, FALSE); //课å èååå§ä¸ºæ æç¶æ
+ gtk_widget_set_sensitive (chatentry, FALSE); //课å èååå§ä¸ºæ æç¶æ
+ }
+ else if(TeacherAgreeChat->Agreechat==1)
+ {
+ chatMode=1;
+ gtk_widget_set_sensitive (sendchatbut, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ gtk_widget_set_sensitive (chatentry, TRUE); //课å èååå§ä¸ºæ æç¶æ
+ }
+
+ break;
+
+ /*case 10022:
+ TRCClientJionInGroupRToAll *NewClient;
+ char *Newstudent[3];
+ NewClient=(TRCClientJionInGroupRToAll *)receive_str->msg;
+ printf("get STUID %d\n",NewClient->ClientInfo.ClientID);
+ printf(" student name is %s ,AVMOde is %d\n",NewClient->ClientInfo.ClientN,NewClient->ClientInfo.AVMode);
+ sprintf(tmp, "%d",NewClient->ClientInfo.ClientID);
+ Newstudent[0]=tmp;
+ printf("student Info ID is %s",Newstudent[0]);
+ Newstudent[1]=NewClient->ClientInfo.ClientN;
+ if(NewClient->ClientInfo.AVMode==0)
+
+ Newstudent[2]=avmode;
+
+ else if(NewClient->ClientInfo.AVMode==1)
+
+ Newstudent[2]=no_avmode;
+
+ gtk_clist_append(GTK_CLIST(stu_clist), studentInfo[index]); //æ·»å å¨çº¿å¦çä¿¡æ¯
+
+ break;*/
+
+ case 1001: //å¾å°æå¸ç«¯åéæ¥çæ¶æ¯
+
+ char TeachMessage[1024];
+ TCRCLTeacherTextBroadcastR *TeacherTextR;
+ TeacherTextR=(TCRCLTeacherTextBroadcastR *)receive_str->msg;
+ strcpy(TeachMessage,"Teacher:");
+ // strcat(TeachMessage,TeacherTextR->TeacherN);
+ strcat(TeachMessage,TeacherTextR->Info);
+ strcat(TeachMessage,"\n");
+ printf("Teacher message is %s\n",TeachMessage);
+ get_text_from_msg(TeachMessage);
+ flush_scrollar();
+ /* textview_mutex.Lock();
+ if(TeacherMode==1)
+ {
+
+ // gtk_adjustment_set_value (GTK_ADJUSTMENT (adj1), y_position);
+
+ gtk_text_buffer_insert(TeachChat_buffer,&TeachChat_end,TeachMessage,-1);
+ gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chatview),&TeachChat_end,&y_position_adj1,&height);
+ // error_info_no=20;
+ }
+ else if(TeacherMode==0)
+ {
+
+ // gtk_adjustment_set_value (GTK_ADJUSTMENT (adj2), y_position);
+
+ gtk_text_buffer_insert(chat_buffer,&chat_end,TeachMessage,-1);
+ gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chat_show),&chat_end,&y_position_adj2,&height);
+ //error_info_no=21;
+ }
+ textview_mutex.Unlock();
+*/
+ break;
+
+ default:
+
+ break;
+ }
+
+ return 0;
+
+}
+
+void client_ts_communicate::get_text_from_msg(char *Message)
+{
+
+ textview_mutex.Lock();
+ if(TeacherMode==1)
+ {
+ gtk_text_buffer_insert(TeachChat_buffer,&TeachChat_end,Message,-1);
+
+ }
+ else if(TeacherMode==0)
+ {
+ gtk_text_buffer_insert(chat_buffer,&chat_end,Message,-1);
+
+ }
+ textview_mutex.Unlock();
+
+}
+void client_ts_communicate::flush_scrollar()
+{
+
+ textview_mutex.Lock();
+ if(TeacherMode==1)
+ {
+
+ //gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chatview),&TeachChat_end,&y_position_adj1,&height);
+ error_info_no=20;
+ }
+ else if(TeacherMode==0)
+ {
+ //gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(chat_show),&chat_end,&y_position_adj2,&height);
+ error_info_no=21;
+ }
+ textview_mutex.Unlock();
+}
Propchange: incubator/bluesky/NCstu-2.0/src/client_communicate.cc
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/bluesky/NCstu-2.0/src/client_communicate.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/client_communicate.h?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/client_communicate.h (added)
+++ incubator/bluesky/NCstu-2.0/src/client_communicate.h Tue Jun 3 19:48:16 2008
@@ -0,0 +1,45 @@
+#ifndef CLIENT_COMMUNICATE_H
+#define CLIENT_COMMUNICATE_H
+
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "singlecomm.h"
+#include "ncclient.hh"
+
+
+////////////////////////// MCU Class////////////////////////////////////
+
+
+
+class client_ts_communicate
+{
+ public:
+ client_ts_communicate();
+ ~client_ts_communicate();
+
+ int establish_connect(LPCTSTR,UINT,UINT nSocketPort=0);
+ int send_mes(struct CRCLMSG,int mes_length);
+ int recevie_msg(char *buf,int buf_length);
+ void get_text_from_msg(char *Message);
+ void flush_scrollar();
+ int close_socket(int nHow);
+
+
+ DWORD Rec_ClientID; //å¦çIDå·
+ TRCClientGetGroupInfoR *GetGroupInfoR; //æ¥æ¶æå¸è¯¾å æ¶æ¯
+ struct CRCLClientJoinInGroupR client_mcu_info;
+
+ private:
+ CClientSocket client_socket;
+ CSingleComm client_socket_thread;
+ JMutex textview_mutex;
+
+
+
+};
+
+
+
+
+
+#endif
Propchange: incubator/bluesky/NCstu-2.0/src/client_communicate.h
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/bluesky/NCstu-2.0/src/clientsocket.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/clientsocket.cpp?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/clientsocket.cpp (added)
+++ incubator/bluesky/NCstu-2.0/src/clientsocket.cpp Tue Jun 3 19:48:16 2008
@@ -0,0 +1,69 @@
+// ClientSocket.cpp: implementation of the CClientSocket class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "client_communicate.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+extern client_ts_communicate client_comm;
+
+
+
+CClientSocket::CClientSocket()
+{
+
+}
+
+CClientSocket::~CClientSocket()
+{
+}
+
+void CClientSocket::OnEvent()
+{
+ //char buffer[100];
+ unsigned long len;
+ if(m_lEvent == 0) //no any event.
+ return;
+ IOCtl(FIONREAD, &len);
+ if(len==0){ //disconnect.
+ Close();
+ printf("\nA client disconnected.");
+ return ;
+ }
+
+ //read incoming data.
+ /*memset(buffer, 0, 100);
+ Receive(buffer, 99);
+ printf("\n%s", buffer);*/
+
+ char buffer[10008]={'\0'};
+ int receive_length=0;
+
+ memset(buffer, '\0', 10008);
+ if( (receive_length=Receive(buffer,10008) )==-1 )
+ {
+ perror("Receive failed!");
+ return ;
+ }
+
+ CRCLMSG* pM = (CRCLMSG*)buffer;
+ printf("message lenth is %d\n",pM->msglen);
+ int index = receive_length;
+ int to_receive_length = pM->msglen +8 - receive_length;
+ while(to_receive_length > 0)
+ {
+ receive_length = Receive(buffer+index,to_receive_length);
+ printf("recv a message lenth is %d\n",receive_length);
+ index += receive_length;
+ to_receive_length -= receive_length;
+ }
+
+ client_comm.recevie_msg(buffer,receive_length); //解ææ¥æ¶çæ°æ®
+
+
+ return ;
+}
Propchange: incubator/bluesky/NCstu-2.0/src/clientsocket.cpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/bluesky/NCstu-2.0/src/clientsocket.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/clientsocket.h?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/clientsocket.h (added)
+++ incubator/bluesky/NCstu-2.0/src/clientsocket.h Tue Jun 3 19:48:16 2008
@@ -0,0 +1,22 @@
+// ClientSocket.h: interface for the CClientSocket class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(CLIENTSOCKET_H)
+#define CLIENTSOCKET_H
+
+
+#include "asyncsocketex.h"
+
+class CClientSocket : public CAsyncSocketEx
+{
+public:
+ CClientSocket();
+ virtual ~CClientSocket();
+
+protected:
+ virtual void OnEvent();
+
+};
+
+#endif // !defined(CLIENTSOCKET_H)
Propchange: incubator/bluesky/NCstu-2.0/src/clientsocket.h
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/bluesky/NCstu-2.0/src/en_de_audio.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/en_de_audio.cpp?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/en_de_audio.cpp (added)
+++ incubator/bluesky/NCstu-2.0/src/en_de_audio.cpp Tue Jun 3 19:48:16 2008
@@ -0,0 +1,1660 @@
+
+#include "en_de_audio.h"
+
+#define ENCODE_ID CODEC_ID_MP2//CODEC_ID_PCM_S16LE
+#define DECODE_ID CODEC_ID_MP3
+
+
+#define STATIC_SLEEP_TIMES 2
+
+
+
+
+extern void PErrorText(const char* error);
+// For CAEncoder class.
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+// for test encode.
+//static FILE* pFile = 0;
+
+
+
+CAEncoder::CAEncoder() : m_soundcard("/dev/dsp")
+{
+
+ m_pCodec = 0;
+ m_pCodecCtx = 0;
+ m_bInit = false;
+
+ m_audio_buf=0;
+ m_fifo=0;
+ m_data = 0;
+ m_datasize =0;
+
+
+// m_hAudioDev = -1;
+
+}
+
+
+CAEncoder::~CAEncoder()
+{
+ /*CAEncoder can't close audio device in ~CAEncoder(),
+ and close audio device in main()*/
+
+ m_bInit = false;
+ CloseAudio();
+
+ if(m_data){
+ free(m_data);
+ m_data = 0;
+ m_datasize = 0;
+ }
+ if(m_pCodecCtx){
+ avcodec_close(m_pCodecCtx);
+ m_pCodecCtx = 0;
+ }
+
+ if (m_audio_buf)
+ free(m_audio_buf);
+
+ if(m_fifo){
+ fifo_free(m_fifo);
+ free(m_fifo);
+ }
+
+
+}
+
+void CAEncoder::CloseAudio()
+{
+}
+
+
+bool CAEncoder::OpenAudio()
+{
+ if(m_soundcard.start_record()<0){
+ printf("\nopen audio error.\n");
+ return false;
+ }
+
+ SOUNDPARAMS sp;
+ sp.format=2;
+
+ sp.channels=STATIC_AUDIO_CHANNEL;
+
+ sp.rate=AUDIO_ENCODE_sample_rate;
+
+// sp.blocksize=640;
+
+// sp.latency=46;
+ m_soundcard.setparams(&sp);
+
+ printf("\nopen audio success.\n");
+ return true;
+
+}
+
+
+
+#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
+bool CAEncoder::Init(enum CodecID nCodecID /*=CODEC_ID_MPEG4*/)
+{
+ m_bInit = false;
+ /*Init for encode*/
+ avienc_init ();
+ av_register_all ();
+
+ if(!OpenAudio())
+ return false;
+
+
+
+ /* find the mpeg4 video encoder */
+ m_pCodec = avcodec_find_encoder(nCodecID);
+ if (!m_pCodec) {
+ PErrorText("codec not found");
+ return false;
+ }
+
+ if(m_pCodecCtx){
+ avcodec_close(m_pCodecCtx);
+ m_pCodecCtx = 0;
+ }
+
+ m_pCodecCtx = avcodec_alloc_context();
+ /* put sample parameters */
+ m_pCodecCtx->codec_id = nCodecID;
+ m_pCodecCtx->codec_type = CODEC_TYPE_AUDIO;
+ m_pCodecCtx->bit_rate = AUDIO_ENCODE_bit_rate;
+ m_pCodecCtx->sample_rate =AUDIO_ENCODE_sample_rate;
+ m_pCodecCtx->channels =STATIC_AUDIO_CHANNEL;
+
+ /* open it */
+ if (avcodec_open(m_pCodecCtx, m_pCodec) < 0) {
+ PErrorText("could not open codec");
+ return false;
+ }
+
+ if (0==m_audio_buf)
+ m_audio_buf = (uint8_t*)av_malloc(2*MAX_AUDIO_PACKET_SIZE);
+
+ if(m_fifo == 0){
+ m_fifo = (FifoBuffer*)malloc(sizeof(FifoBuffer));
+ fifo_init(m_fifo,10000);
+ /*m_fifo->buffer = (uint8_t*)malloc(4096);
+ m_fifo->rptr = (uint8_t*)malloc(4096);
+ m_fifo->wptr = (uint8_t*)malloc(4096);
+ m_fifo->end = (uint8_t*)malloc(4096);*/
+ }
+
+
+
+ m_bInit = true;
+ return true;
+}
+
+/*void SaveToFile(uint8_t* data, int len)
+{
+ static FILE* f=NULL;
+// f = (FILE*)0;
+ if(f==NULL){
+ f = fopen("daneaudio_A.mp3", "wb+");
+ if(f==NULL)
+ exit(100);
+ }
+ if(f){
+ fwrite(data, len, 1, f);
+ }
+ else{
+ exit(100);
+ }
+
+}
+*/
+
+int CAEncoder::EncodeProcess(uint8_t* data, uint8_t *pOutBuf[2], int nOutsize)
+{
+// int ret;
+ int size_out = nOutsize;
+ int loop_times=0;
+
+ if(!m_bInit)
+ return -1;
+
+
+ /* now encode as many frames as possible */
+ if (m_pCodecCtx->frame_size > 1) {
+ //printf("nOutsize is %d\n",nOutsize);
+ //printf("fifo ptr is %d\n",m_fifo->wptr - m_fifo->rptr);
+ //printf("fifo mini is %d\n",m_fifo->end - m_fifo->wptr);
+ fifo_write(m_fifo, data, nOutsize,
+ &m_fifo->wptr);
+ //printf("after fifo mini is %d\n",m_fifo->end - m_fifo->wptr);
+ //printf("after size is %d\n",m_fifo->wptr - m_fifo->rptr);
+
+ int frame_bytes = m_pCodecCtx->frame_size *2 * m_pCodecCtx->channels;
+ //int frame_bytes = fifo_size(m_fifo,m_fifo->rptr);
+ //printf("frame_bytes is %d\n",frame_bytes);
+ while (fifo_read(m_fifo, m_audio_buf, frame_bytes,
+ &m_fifo->rptr) == 0) {
+
+ m_encode_length[loop_times] = avcodec_encode_audio(m_pCodecCtx, pOutBuf[loop_times], 4*MAX_AUDIO_PACKET_SIZE,
+ (short *)m_audio_buf);
+ ++loop_times;
+ //printf("(%d)fifo: audio_out_size\n", loop_times);
+
+ //SaveToFile(pOutBuf[loop_times-1], ret);
+
+ if(loop_times>=2)
+ break;
+
+ //av_write_frame(s, ost->index, audio_out, ret);
+ }
+ }
+ else {
+ /* output a pcm frame */
+ /* XXX: change encoding codec API to avoid this ? */
+ switch(m_pCodecCtx->codec->id) {
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ break;
+ default:
+ size_out = size_out >> 1;
+ break;
+ }
+ m_encode_length[0] = avcodec_encode_audio(m_pCodecCtx, pOutBuf[0], size_out,
+ (short *)data);
+ loop_times=1;
+ printf("now encode here!\n");
+ //SaveToFile( audio_out, ret);
+ }
+
+ return loop_times;
+ //memcpy(data, pOutBuf, nOutsize);
+ //return nOutsize;
+
+ //ret = avcodec_encode_audio (m_pCodecCtx,
+ // pOutBuf,
+ // nOutsize, //must be the same to read() in CAEncoder::Capture().
+ // (short *)data);
+
+ // printf("\naudio encode %d bytes\n", ret);
+ // if(ret>0)
+ // SaveToFile(pOutBuf, ret);
+ //return ret;
+}
+
+int CAEncoder::Capture(uint8_t** pOutBuf, int &size)
+{
+ int ret;
+ static uint8_t buf[10000];
+ if(!m_bInit)
+ return -1;
+/*
+ ret = read(m_hAudioDev, buf, 1280); //must be the same to encodeprocess.
+ if(ret>0){
+ *pOutBuf = buf;
+ size = ret;
+ return 0;
+ }
+*/
+ m_soundcard.sounddata(buf, ret);
+// printf("\naudio capture %d bytes\n", ret);
+ if(ret>0){
+ *pOutBuf = buf;
+ size = ret;
+
+// SaveToFile(*pOutBuf, ret);
+ return ret;
+ }
+
+ return -1;
+}
+
+
+
+// For CADecoder class.
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+CADecoder::CADecoder()
+{
+// static int siSeq = 0;
+ m_pCodec = 0;
+ m_pCodecCtx = 0;
+// m_pOutFrame = 0;
+ m_pSDLBuf = 0;
+// m_pFrameBuf = 0;
+ m_bInit = false;
+
+ /*m_stream = 0;
+
+ if(g_arts_count<=0){
+ if(g_arts_count<0)
+ g_arts_count = 0;
+ if(arts_init()==0){
+ g_arts_count++;
+ }
+ }
+ siSeq++;
+ sprintf(m_pName,"RC_%d",siSeq);*/
+}
+
+CADecoder::~CADecoder()
+{
+
+ /*CADecoder can't close audio device in ~CADecoder(),
+ and close audio device in main()*/
+// m_hAudioDev = 0;
+
+
+ m_bInit = false;
+
+ //CloseAudio();
+
+ if(m_pSDLBuf){
+ free(m_pSDLBuf);
+ m_pSDLBuf = 0;
+ }
+
+
+ if(m_pCodecCtx){
+ avcodec_close(m_pCodecCtx);
+ m_pCodecCtx = 0;
+ }
+
+ /*g_arts_count--;
+ if(g_arts_count<=0){
+ arts_free();
+ }*/
+
+
+}
+
+/*void CADecoder::CloseAudio()
+{
+ if(m_stream>0){
+ arts_close_stream(m_stream);
+ }
+
+ m_stream = 0;
+
+}*/
+
+//#define ARTS_PACKETS 10 /* Number of audio packets */
+//#define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
+/*bool CADecoder::OpenAudio()
+{
+/* int errorcode;
+
+ errorcode = arts_init();
+ if(errorcode != 0){
+ PErrorText("\nOpenAudio: arts_init Error.\n");
+ return false;
+ }
+* /
+
+ m_stream = arts_play_stream(AUDIO_DECODE_sample_rate, 16, 1, m_pName);
+ arts_stream_set(m_stream,ARTS_P_BLOCKING,0);
+
+
+
+ if(m_stream <= 0 ){
+ PErrorText("\nOpenAudio: arts_play_stream Error.\n");
+ return false;
+ }
+ arts_stream_set(m_stream, ARTS_P_BLOCKING, 1);
+ arts_stream_set(m_stream, ARTS_P_BUFFER_TIME, 500);
+ int frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
+ arts_stream_set(m_stream, ARTS_P_PACKET_SETTINGS, frag_spec);
+
+ printf("\narts_play_stream ok\n");
+ return true;
+}*/
+
+bool CADecoder::Init(enum CodecID nCodecID/* = CODEC_ID_MP3*/, int nOutBufSize /*= SDLBufSize*/)
+{
+ m_bInit = false;
+
+ avcodec_init();
+ avcodec_register_all();
+
+
+ //malloc SDLBuf.
+ if(m_pSDLBuf){
+ free(m_pSDLBuf);
+ m_pSDLBuf = 0;
+ }
+
+
+ m_pSDLBuf = (uint8_t*)malloc(nOutBufSize*sizeof(uint8_t));
+ if(m_pSDLBuf == 0){
+ PErrorText("OutBuf malloc failed!");
+ return false;
+ }
+
+
+ // find the video decoder
+ m_pCodec = avcodec_find_decoder(nCodecID);
+ if (!m_pCodec) {
+ PErrorText("Codec not found");
+ return false;
+ }
+
+ if(m_pCodecCtx){
+ avcodec_close(m_pCodecCtx);
+ m_pCodecCtx = 0;
+ }
+ m_pCodecCtx = avcodec_alloc_context();
+
+ // frames per second
+ m_pCodecCtx->frame_rate = A_DECODE_framerate;
+ m_pCodecCtx->frame_rate_base= A_DECODE_frame_rate_base;
+ // emit one intra frame every ten frames
+ m_pCodecCtx->gop_size = A_DECODE_gop_size;
+// m_pCodecCtx->max_b_frames=1;
+
+ m_pCodecCtx->bit_rate = AUDIO_DECODE_bit_rate;
+ m_pCodecCtx->sample_rate = AUDIO_DECODE_sample_rate;
+ m_pCodecCtx->channels = STATIC_AUDIO_CHANNEL;
+
+ m_pCodecCtx->codec_type = CODEC_TYPE_AUDIO;
+
+ // we dont send complete frames
+ if(m_pCodec->capabilities&CODEC_CAP_TRUNCATED)
+ m_pCodecCtx->flags|= CODEC_FLAG_TRUNCATED;
+
+ // open it
+ if (avcodec_open(m_pCodecCtx, m_pCodec) < 0) {
+ PErrorText("could not open codec");
+ return false;
+ }
+
+ m_bInit = true;
+ return true;
+}
+
+int CADecoder::DecodeProcess(uint8_t *encodeddata_a, const int encodeddatasize_a)//,char *outbuf)
+{
+
+ //static JMutex arts_writemutex;
+
+
+ int len;
+ int encodedAudioSize;
+ int outAudioBufSize ;
+ int kkk;
+
+ if(!m_bInit){
+ return -1;
+ }
+
+
+ /*if(!arts_writemutex.IsInitialized()){
+ if(!arts_writemutex.Init()){
+ PErrorText("\nDecodeProcess: arts_writemutex Init error\n");
+ return -1;
+
+ }
+ }*/
+
+ encodedAudioSize = encodeddatasize_a;
+ len = 0;
+ kkk = 0;
+ while(encodedAudioSize > 0){
+ len = avcodec_decode_audio(m_pCodecCtx, (short *)m_pSDLBuf, &outAudioBufSize,
+ encodeddata_a+kkk, encodedAudioSize);
+ //len = avcodec_decode_audio(m_pCodecCtx, (short *)outbuf, &outAudioBufSize,
+ // encodeddata_a+kkk, encodedAudioSize);
+ if(len < 0){
+ PErrorText("Error While Decoding Audio");
+ return -2;
+ }
+
+ encodedAudioSize -= len;
+ kkk += len;
+ }
+
+ //short *s_chAudioBuf=new short(outAudioBufSize);
+ /*static int s_iloops=0;
+ static char s_chAudioBuf[STATIC_AUDIO_FRAMES*2*4096];
+ static int s_AudioBuflength=0;
+ memcpy(s_chAudioBuf+s_AudioBuflength,m_pSDLBuf,outAudioBufSize);
+ s_AudioBuflength+=outAudioBufSize;
+ s_iloops++;
+
+
+ if( (m_stream>0) && (s_iloops>=STATIC_AUDIO_FRAMES) && (s_AudioBuflength>0) ){
+ arts_writemutex.Lock();
+ static int64_t pre, cur,inteval;
+ pre = av_gettime();
+ //arts_write(m_stream, m_pSDLBuf, outAudioBufSize);
+ arts_write(m_stream, s_chAudioBuf, s_AudioBuflength);
+ s_iloops=0;
+ s_AudioBuflength=0;
+ cur = av_gettime();
+ inteval = (cur-pre);
+ //printf("here!\n");
+ //printf("artsd write cost %d\n",inteval);
+
+ std::cout<<"artsd cost time is "<<inteval<<std::endl;
+ arts_writemutex.Unlock();
+
+ }*/
+
+ return outAudioBufSize;
+}
+
+
+
+//CAudioSender class.
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+CAudioSender::CAudioSender()
+{
+ stop = false;
+ m_bIsRecord = false;
+ m_bInit = 0;
+ m_sendpause = false;
+
+ m_hFile = 0;
+#if (defined(WIN32) || defined(_WIN32_WCE))
+ timeinit.Dummy();
+#endif // WIN32 || _WIN32_WCE
+}
+
+CAudioSender::~CAudioSender()
+{
+ //first stop thread, because m_pOutBuf is being used by Thread();
+ Stop();
+
+ //close file.
+ if(m_hFile){
+ fclose(m_hFile);
+ m_hFile = 0;
+ }
+
+ //free buffer.
+ if(m_pOutBuf[0]!=0)
+ free(m_pOutBuf[0]);
+
+ if(m_pOutBuf[1]!=0)
+ free(m_pOutBuf[1]);
+}
+
+#define MAX_PACKET_SIZE 10*1024
+bool CAudioSender::Init(int nPort)
+{
+ if(m_bInit)
+ return true;
+
+ //init rtpsession.
+ RTPSessionParams sessParams1;
+ sessParams1.SetOwnTimestampUnit(1.0 / 30.0); //30 video frames per second
+ sessParams1.SetUsePollThread(0); //background thread to call virtual callbacks - set by default, but just to be sure
+ sessParams1.SetMaximumPacketSize(MAX_PACKET_SIZE);
+ //setup transmission parameters
+ RTPUDPv4TransmissionParams transParams1;
+ transParams1.SetPortbase(nPort);
+ //CREATE THE SESSION
+ int status1 = m_fecrtpsession.Create(sessParams1, &transParams1);
+ if (status1){
+// ReportError(status1);
+ return false; //unable to create the session
+ }
+ //must set for fec SendFECPacket.
+ m_fecrtpsession.SetDefaultMark(true);
+ m_fecrtpsession.SetDefaultPayloadType(1);
+ m_fecrtpsession.SetDefaultTimestampIncrement(0);
+
+ for(int i=0;i<=1;i++){
+ if(m_pOutBuf[i]==0){
+ m_pOutBuf[i] = (uint8_t*)malloc(CAEncoder::A_OutBufSize);
+ if(m_pOutBuf[i]==0){
+ return false;
+ }
+ }
+ }
+
+ //Init vencoder.
+ if(!m_aencoder.Init(ENCODE_ID)){
+// if(!m_aencoder.Init(CODEC_ID_MP2)){
+ return false;
+ }
+
+ m_bIsRecord = false;
+ m_bInit = true;
+ return m_bInit;
+}
+
+
+
+typedef struct
+{
+uint16_t wFormatag;//ç¼ç æ ¼å¼ï¼å
æ¬WAVE_FORMAT_PCMï¼WAVEFORMAT_ADPCMç
+uint16_t nChannls;//声éæ°ï¼å声é为1ï¼å声é为2;
+uint32_t nSamplesPerSec;//éæ ·é¢çï¼
+uint32_t nAvgBytesperSec;//æ¯ç§çæ°æ®éï¼
+uint16_t nBlockAlign;//å对é½ï¼
+}WAVEFORMAT;
+
+
+typedef struct
+{
+WAVEFORMAT wf;//æ³¢å½¢æ ¼å¼ï¼
+uint16_t wBitsPerSample;//WAVEæ件çéæ ·å¤§å°ï¼
+}PCMWAVEFORMAT;
+
+
+int CAudioSender::Start(char* szFile /* =0 */, bool bIsRecord /* =false */)
+{
+ if(!m_bInit)
+ return -1;
+
+ if (JThread::IsRunning())
+ return 0;
+
+ if (!stopmutex.IsInitialized())
+ {
+ if (stopmutex.Init() < 0)
+ return -2;
+ }
+
+ stop = false;
+
+ if (!m_sendpausemutex.IsInitialized())
+ {
+ if (m_sendpausemutex.Init() < 0)
+ return -2;
+ }
+
+ m_sendpause = false;
+
+ if (!m_recordmutex.IsInitialized())
+ {
+ if (m_recordmutex.Init() < 0)
+ return -2;
+ }
+
+ m_bIsRecord = bIsRecord;
+
+ if(bIsRecord && szFile != 0){
+ if(m_hFile){
+ fclose(m_hFile);
+ m_hFile = 0;
+ }
+
+ m_hFile = fopen(szFile, "wb");
+/* //wav format header.
+ PCMWAVEFORMAT pcmwaveformat;
+ pcmwaveformat.wBitsPerSample = 16000;
+ pcmwaveformat.wf
+ fwrite("RIFF", 4, 1, m_hFile);
+ fwrite("0000", 4, 1, m_hFile);
+ fwrite("WAVE", 4, 1, m_hFile);
+ fwrite("fmt", 4, 1, m_hFile);
+ uint32_t pcmformatsize = sizeof(pcmwaveformat);
+ fwrite(&pcmformatsize, 4, 1, m_hFile);
+
+ //wav format header.
+*/
+ if(m_hFile==0){
+ return -3;
+ }
+
+ m_bIsRecord = true;
+ }
+
+ if (JThread::Start() < 0){
+ m_bIsRecord = false;
+ return -6;
+ }
+
+ return 0;
+}
+
+void CAudioSender::Stop()
+{
+ if (!IsRunning())
+ return;
+
+ stopmutex.Lock();
+ stop = true;
+ stopmutex.Unlock();
+
+ //wait for two minute;
+/* sleep(2);
+ if (JThread::IsRunning())
+ {
+#ifndef _WIN32_WCE
+ std::cerr << "RTPPollThread: Warning! Having to kill thread!" << std::endl;
+#endif // _WIN32_WCE
+ JThread::Kill();
+ }
+*/
+ int icount=0;
+ while(1)
+ {
+ if(icount>100){
+ if(JThread::IsRunning())
+ {
+
+ JThread::Kill();
+
+ }
+ break;
+ }
+ else{
+ if(!JThread::IsRunning())
+ break;
+ icount++;
+ usleep(10000);
+ }
+ }
+ stop = false;
+
+
+ //close file.
+ if(m_hFile){
+ fclose(m_hFile);
+ m_hFile = 0;
+ }
+
+ m_bIsRecord = false;
+}
+
+void CAudioSender::Pause()
+{
+ if(!m_bInit)
+ return ;
+ m_sendpausemutex.Lock();
+ m_sendpause = true;
+ m_sendpausemutex.Unlock();
+
+}
+
+void CAudioSender::Resume()
+{
+ if(!m_bInit)
+ return ;
+
+ m_sendpausemutex.Lock();
+ m_sendpause = false;
+ m_sendpausemutex.Unlock();
+
+}
+
+void CAudioSender::Record(bool bInRecord /* =true */)
+{
+ if(!m_bInit)
+ return ;
+
+ m_recordmutex.Lock();
+ m_bIsRecord = bInRecord;
+ m_recordmutex.Unlock();
+
+}
+
+void *CAudioSender::Thread()
+{
+ uint8_t * data;
+ int datasize;
+ int OutBufSzie;
+ int status;
+ int i=0;
+
+ JThread::ThreadStarted();
+
+ bool stopthread;
+
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+
+ bool sendpause;
+
+ m_sendpausemutex.Lock();
+ sendpause = m_sendpause;
+ m_sendpausemutex.Unlock();
+
+
+ bool isrecord;
+ m_recordmutex.Lock();
+ isrecord = m_bIsRecord;
+ m_recordmutex.Unlock();
+
+ int64_t pre_time, cur_time;
+ useconds_t delay=0;
+ pre_time = av_gettime();
+ while (!stopthread)
+ {
+
+ cur_time = av_gettime();
+ delay = cur_time-pre_time;
+ if(delay < 20000*STATIC_SLEEP_TIMES){
+ usleep(20000*STATIC_SLEEP_TIMES-delay);
+ //printf("sleep!\n");
+
+ }
+ pre_time = av_gettime();
+ //usleep(5000); //new modify
+
+ if ((status = m_aencoder.Capture(&data, datasize)) < 0)
+ {
+ printf("\naudio capture failed");
+ stopthread = true;
+ }
+ else{
+
+// printf("\nsatus %d", status);
+ if(datasize<=0)
+ continue;
+ OutBufSzie = datasize;
+ if ((status = m_aencoder.EncodeProcess(data, m_pOutBuf, OutBufSzie)) < 0)
+ {
+ printf("\naudio EncodeProcess failed");
+ stopthread = true;
+ }
+ else{
+ if(status>0){
+
+ if(!sendpause){
+ static int s_iTemp=0;
+ s_iTemp++;
+
+ for(i=0;i<status;i++){
+
+ static char temp_buf[1000];
+ int *temp_p=(int *)temp_buf;
+
+ //printf("now send sequen is %d\n",s_iTemp);
+
+ *temp_p=s_iTemp;
+ memcpy(temp_buf+sizeof(int),m_pOutBuf[i],m_aencoder.encodelength(i));
+ m_fecrtpsession.SendPacket(temp_buf, m_aencoder.encodelength(i)+sizeof(int));
+ //printf("\n<<<<<<<<<<<<<<<<audion send<<<<<<<<<<<<<<<: %d bytes encoded.", status);
+
+ //} new modify
+ if(m_hFile!=0 && isrecord){
+ //printf("\n<<<<<<<<<<<<<<<<audion send<<<<<<<<<<<<<<<%d \n", sizeof(m_pOutBuf[i]));
+ fwrite(m_pOutBuf[i], m_aencoder.encodelength(i), 1, m_hFile);
+ }
+ }//new modify
+ }
+ }
+
+ m_recordmutex.Lock();
+ isrecord = m_bIsRecord;
+ m_recordmutex.Unlock();
+
+
+ m_sendpausemutex.Lock();
+ sendpause = m_sendpause;
+ m_sendpausemutex.Unlock();
+
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+ }
+ }
+
+ }
+ printf("\naudio thread stop normally.");
+ return 0;
+}
+
+bool CAudioSender::AddDestination(const RTPIPv4Address &des)
+{
+ if(!m_bInit)
+ return false;
+ if(m_fecrtpsession.AddDestination(des)<0)
+ return false;
+
+ return true;
+}
+
+void CAudioSender::ClearDestinations()
+{
+ if(!m_bInit)
+ return ;
+ m_fecrtpsession.ClearDestinations();
+}
+
+
+//CStuAudioSender class.
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+CStuAudioSender::CStuAudioSender()
+{
+ stop = false;
+ m_bInit = 0;
+ m_sendpause = false;
+
+ m_pOutBuf[0]=0;
+ m_pOutBuf[1]=0;
+
+#if (defined(WIN32) || defined(_WIN32_WCE))
+ timeinit.Dummy();
+#endif // WIN32 || _WIN32_WCE
+}
+
+CStuAudioSender::~CStuAudioSender()
+{
+ //first stop thread, because m_pOutBuf is being used by Thread();
+ Stop();
+
+
+ //free buffer.
+ if(m_pOutBuf[0]!=0)
+ free(m_pOutBuf[0]);
+ if(m_pOutBuf[1]!=0)
+ free(m_pOutBuf[1]);
+}
+
+bool CStuAudioSender::Init(int nPort)
+{
+ if(m_bInit)
+ return true;
+
+ //init rtpsession.
+ RTPSessionParams sessParams1;
+ sessParams1.SetOwnTimestampUnit(1.0 / 30.0); //30 video frames per second
+ sessParams1.SetUsePollThread(0); //background thread to call virtual callbacks - set by default, but just to be sure
+ sessParams1.SetMaximumPacketSize(MAX_PACKET_SIZE);
+ //setup transmission parameters
+ RTPUDPv4TransmissionParams transParams1;
+ transParams1.SetPortbase(nPort);
+ //CREATE THE SESSION
+ int status1 = m_fecrtpsession.Create(sessParams1, &transParams1);
+ if (status1){
+// ReportError(status1);
+ return false; //unable to create the session
+ }
+ //must set for fec SendFECPacket.
+ m_fecrtpsession.SetDefaultMark(true);
+ m_fecrtpsession.SetDefaultPayloadType(1);
+ m_fecrtpsession.SetDefaultTimestampIncrement(0);
+
+ for(int i=0;i<=1;i++){
+ if(m_pOutBuf[i]==0){
+ m_pOutBuf[i] = (uint8_t*)malloc(CAEncoder::A_OutBufSize);
+ if(m_pOutBuf[i]==0){
+ return false;
+ }
+
+ }
+ }
+ //Init vencoder.
+ if(!m_aencoder.Init(ENCODE_ID)){
+ return false;
+ }
+
+ m_bInit = true;
+ return m_bInit;
+}
+
+
+
+int CStuAudioSender::Start(char* szFile /* =0 */, bool bIsRecord /* =false */)
+{
+ if(!m_bInit)
+ return -1;
+
+ if (JThread::IsRunning())
+ return 0;
+
+ if (!stopmutex.IsInitialized())
+ {
+ if (stopmutex.Init() < 0)
+ return -2;
+ }
+
+ stop = false;
+
+
+ if (!m_sendpausemutex.IsInitialized())
+ {
+ if (m_sendpausemutex.Init() < 0)
+ return -2;
+ }
+
+ m_sendpause = false;
+
+
+ if (JThread::Start() < 0){
+ return -6;
+ }
+
+ return 0;
+}
+
+void CStuAudioSender::Stop()
+{
+ if (!IsRunning())
+ return;
+
+ stopmutex.Lock();
+ stop = true;
+ stopmutex.Unlock();
+
+ //wait for two minute;
+/* sleep(1);
+ if (JThread::IsRunning())
+ {
+#ifndef _WIN32_WCE
+ std::cerr << "RTPPollThread: Warning! Having to kill thread!" << std::endl;
+#endif // _WIN32_WCE
+ JThread::Kill();
+ }
+*/
+ int icount=0;
+ while(1)
+ {
+ if(icount>100){
+ if(JThread::IsRunning())
+ {
+
+ JThread::Kill();
+
+ }
+ break;
+ }
+ else{
+ if(!JThread::IsRunning())
+ break;
+ icount++;
+ usleep(10000);
+ }
+ }
+ stop = false;
+
+
+}
+
+void CStuAudioSender::Pause()
+{
+ if(!m_bInit)
+ return ;
+ m_sendpausemutex.Lock();
+ m_sendpause = true;
+ m_sendpausemutex.Unlock();
+
+}
+
+void CStuAudioSender::Resume()
+{
+ if(!m_bInit)
+ return ;
+
+ m_sendpausemutex.Lock();
+ m_sendpause = false;
+ m_sendpausemutex.Unlock();
+
+}
+
+
+void *CStuAudioSender::Thread()
+{
+ uint8_t * data;
+ int datasize;
+ int OutBufSzie;
+ int status;
+
+ JThread::ThreadStarted();
+
+ bool stopthread;
+
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+
+
+ bool sendpause;
+
+ m_sendpausemutex.Lock();
+ sendpause = m_sendpause;
+ m_sendpausemutex.Unlock();
+
+
+ int64_t pre_time, cur_time;
+ useconds_t delay;
+ pre_time = av_gettime();
+ while (!stopthread)
+ {
+
+ cur_time = av_gettime();
+ delay = cur_time-pre_time;
+ if(delay < 20000*STATIC_SLEEP_TIMES){
+ usleep(20000*STATIC_SLEEP_TIMES-delay);
+ pre_time = av_gettime();
+ }
+ //usleep(5000);
+
+ if ((status = m_aencoder.Capture(&data, datasize)) < 0)
+ {
+ printf("\naudio capture failed");
+ stopthread = true;
+ }
+ else{
+
+// printf("\nsatus %d", status);
+ if(datasize<=0)
+ continue;
+ OutBufSzie = datasize;
+ if ((status = m_aencoder.EncodeProcess(data, m_pOutBuf, OutBufSzie)) < 0)
+ {
+ printf("\naudio EncodeProcess failed");
+ stopthread = true;
+ }
+ else{
+ if(status>0){
+ if(!sendpause){
+ static int s_iTemp1=0;
+ s_iTemp1++;
+ for(int i=0;i<status;i++){
+ static char temp_buf[1000];
+ int *temp_p=(int *)temp_buf;
+ static int s_iTemp1=0;
+ s_iTemp1++;
+
+ //printf("now send sequen is %d\n",s_iTemp1);
+ *temp_p=s_iTemp1;
+ memcpy(temp_buf+sizeof(int),m_pOutBuf[i],m_aencoder.encodelength(i));
+ m_fecrtpsession.SendPacket(temp_buf, m_aencoder.encodelength(i)+sizeof(int));
+ }
+ //usleep(20000);
+ }
+ }
+
+ m_sendpausemutex.Lock();
+ sendpause = m_sendpause;
+ m_sendpausemutex.Unlock();
+
+
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+ }
+ }
+
+ }
+ printf("\nAudio capture thread stoped.\n");
+ return 0;
+}
+
+bool CStuAudioSender::AddDestination(const RTPIPv4Address &des)
+{
+ if(!m_bInit)
+ return false;
+ if(m_fecrtpsession.AddDestination(des)<0)
+ return false;
+
+ return true;
+}
+
+void CStuAudioSender::ClearDestinations()
+{
+ if(!m_bInit)
+ return ;
+ m_fecrtpsession.ClearDestinations();
+}
+
+
+
+
+
+//CAudioReceiver class.
+//CAudioWriteThread CAudioReceiver::m_artswrite(MAX_ARTS_WRITE_FRAMES);
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+CAudioReceiver::CAudioReceiver():m_artswrite(MAX_ARTS_WRITE_FRAMES) //define in en_de_sendthread.h
+{
+ m_bInit = false;
+
+ m_iloops=0;
+
+ m_AudioBuflength=0;
+
+ static int s_itemp=0;
+ m_intNo=0;
+ sprintf(m_charNO,"%d ",s_itemp);
+ s_itemp++;
+}
+
+CAudioReceiver::~CAudioReceiver()
+{
+ m_artswrite.CloseAudio();
+}
+
+bool CAudioReceiver::Init()
+{
+ if(m_bInit)
+ return m_bInit;
+
+ //init video decoder.
+ if(!m_adecoder.Init(DECODE_ID)){
+ return false;
+ }
+
+ if(!m_artswrite.Init())
+ return false;
+
+ m_artswrite.OpenAudio();
+
+
+ m_bInit = true;
+ return m_bInit;
+
+}
+
+int CAudioReceiver::Start(int nPort)
+{
+ if(!m_bInit)
+ return -1;
+
+
+ if(m_artswrite.Start() < 0){
+ return -6;
+ }
+
+ if(IsActive())
+ return 0;
+
+ //init rtpsession.
+ RTPSessionParams sessParams1;
+ sessParams1.SetOwnTimestampUnit(1.0 / 30.0); //30 video frames per second
+ sessParams1.SetUsePollThread(1); //background thread to call virtual callbacks - set by default, but just to be sure
+ sessParams1.SetMaximumPacketSize(MAX_PACKET_SIZE);
+ //setup transmission parameters
+ RTPUDPv4TransmissionParams transParams1;
+ transParams1.SetPortbase(nPort);
+ //CREATE THE SESSION
+ int status1 = Create(sessParams1, &transParams1);
+ if (status1){
+// ReportError(status1);
+ return -2; //unable to create the session
+ }
+
+
+ return 0;
+}
+
+void CAudioReceiver::Stop()
+{
+ m_artswrite.Stop();
+
+
+ Destroy();
+}
+
+void CAudioReceiver::OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
+{
+// static int i=0;
+// printf("\n%d\n", i++)
+ //static int64 s_cur_time=av_gettime();
+// static int64 s_pre_time = av_gettime();
+
+// s_pre_time=av_gettime();
+
+ //int *iTemp=0;
+ //iTemp=(int *)pack->GetPayloadData();
+
+ //m_intNo++;
+ //if(m_intNo>=10)
+ // printf("%s now receive audio sequen is %d\n",m_charNO,*iTemp);
+
+ int iDecodeLength=0;
+
+ //char chAudioBuf[2*4096];
+
+ iDecodeLength=m_adecoder.DecodeProcess(pack->GetPayloadData()+sizeof(int), pack->GetPayloadLength()-sizeof(int) );//,chAudioBuf);
+
+
+ memcpy(m_chAudioBuf+m_AudioBuflength,m_adecoder.m_pSDLBuf,iDecodeLength);
+ m_AudioBuflength+=iDecodeLength;
+ m_iloops++;
+
+
+ if(m_iloops>=STATIC_AUDIO_FRAMES){
+ m_artswrite.SetData( (uint8_t *)m_chAudioBuf,m_AudioBuflength);
+ m_iloops=0;
+ m_AudioBuflength=0;
+
+ }
+
+
+// s_cur_time=av_gettime();
+}
+
+
+
+
+//oss
+/*
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+
+#ifdef HAVE_SOUNDCARD_H
+# include <soundcard.h>
+#endif
+#ifdef HAVE_SYS_SOUNDCARD_H
+# include <sys/soundcard.h>
+#endif
+
+*/
+#ifndef OSS_GETVERSION
+#define OSS_GETVERSION _IOR('M',118,int)
+#endif
+
+/* ---------------------------------------------------------------------- */
+
+Soundcard::Soundcard(const char *dev)
+{
+ if (dev)
+ strcpy(devname,dev);
+ else
+ strcpy(devname,"/dev/dsp");
+
+ driver_name[0] = '\0';
+
+ stat = STATUS_CLOSED;
+ get_capabilities();
+ channels = 1;//STATIC_AUDIO_CHANNEL;
+ rate = 22050;
+ fd = -1;
+}
+
+Soundcard::~Soundcard()
+{
+ /* nothing */
+ close_dev();
+}
+
+int
+Soundcard::start_record()
+{
+ switch (stat) {
+ case STATUS_CLOSED:
+ if (!init_done)
+ get_capabilities();
+ if (!init_done)
+ return -1;
+ return open_dev(TRUE);
+ case STATUS_RECORD:
+ return 0;
+ case STATUS_PLAYBACK:
+ close_dev();
+ return open_dev(TRUE);
+ }
+ return -1;
+}
+
+int
+Soundcard::start_playback()
+{
+ switch (stat) {
+ case STATUS_CLOSED:
+ if (!init_done)
+ get_capabilities();
+ if (!init_done)
+ return -1;
+ return open_dev(FALSE);
+ case STATUS_RECORD:
+ close_dev();
+ return open_dev(FALSE);
+ case STATUS_PLAYBACK:
+ return 0;
+ }
+ return -1;
+}
+
+int
+Soundcard::kill_buffer()
+{
+ ioctl(fd,SNDCTL_DSP_RESET,0);
+ return 0;
+}
+
+int
+Soundcard::stop()
+{
+ if (stat != STATUS_CLOSED)
+ close_dev();
+ return 0;
+}
+
+/* ---------------------------------------------------------------------- */
+
+void
+Soundcard::get_capabilities()
+{
+ int i,dsp;
+ int try_afmt;
+ int try_channels;
+
+ afmt = 0;
+ if (-1 != (dsp = open(devname, O_RDONLY))) {
+
+ ioctl(dsp, SNDCTL_DSP_SETFMT, &afmt); /* current */
+ ioctl(dsp, SNDCTL_DSP_GETFMTS, &afmt_hw); /* hardware cap */
+ afmt_sw = 0;
+
+ for (i = 0; i < 16 /* XXX */; i++) {
+ try_afmt = (1<<i);
+ if (-1 == ioctl(dsp, SNDCTL_DSP_SETFMT, &try_afmt))
+ continue;
+ if (try_afmt != (1<<i))
+ continue;
+ afmt_sw |= try_afmt;
+ }
+
+ try_channels = 2;
+ if (-1 != ioctl(dsp, SNDCTL_DSP_CHANNELS, &try_channels) &&
+ 2 == try_channels)
+ channels_hw = 2;
+ else
+ channels_hw = 1;
+
+ /* version check */
+ if (-1 == ioctl(dsp,OSS_GETVERSION,&i)) {
+ strcpy(driver_name,"OSS (version unknown)");
+ } else {
+ sprintf(driver_name,"OSS %d.%d.%d%c",
+ (i>>16) & 0xff,(i>>8) & 0xff,(i>>4) & 0xf,(i&0xf)+'a');
+ }
+
+ close(dsp);
+ init_done = 1;
+
+ } else {
+ init_done = 0;
+ }
+}
+
+int
+Soundcard::has_channels()
+{
+ if (!init_done)
+ return -1;
+ return channels_hw;
+}
+
+int
+Soundcard::has_format(int f)
+{
+ if (!init_done)
+ return -1;
+ switch (f) {
+ case FMT_8BIT:
+ return (afmt_hw & AFMT_U8) ? 1 : 0;
+ break;
+ case FMT_16BIT:
+ return (afmt_hw & AFMT_S16_LE) ? 1 : 0;
+ break;
+ case FMT_MULAW:
+ case FMT_ALAW:
+ default:
+ return 0;
+ }
+}
+
+char*
+Soundcard::driver()
+{
+ return driver_name;
+}
+
+int
+Soundcard::open_dev(int record)
+{
+ struct SOUNDPARAMS p;
+ int frag,rrate;
+
+ if (-1 == (fd = open(devname,record ? O_RDONLY : O_WRONLY)))
+ goto err;
+ fcntl(fd,F_SETFD,FD_CLOEXEC);
+
+ /* try to get ~50 ms latency */
+ blocksize = 50*channels*rate/1000;
+ if (afmt == AFMT_U16_BE || afmt == AFMT_S16_BE ||
+ afmt == AFMT_U16_LE || afmt == AFMT_S16_LE)
+ blocksize *= 2;
+ for (frag = 0; blocksize != 1; frag++)
+ blocksize >>= 1;
+#if 0
+ fprintf(stderr,"asking for %d byte blocksize\n",1 << frag);
+#endif
+ frag |= 0x7fff0000;
+ if (-1 == ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag))
+ perror("ioctl SNDCTL_DSP_SETFRAGMENT");
+
+ rrate = rate;
+ if (-1 == ioctl(fd, SNDCTL_DSP_SETFMT, &afmt)) {
+ perror("ioctl SNDCTL_DSP_SETFMT");
+ goto err;
+ }
+ if (-1 == ioctl(fd, SNDCTL_DSP_CHANNELS, &channels)) {
+ perror("ioctl SNDCTL_DSP_SETFMT");
+ goto err;
+ }
+ if (-1 == ioctl(fd, SNDCTL_DSP_SPEED, &rrate)) {
+ perror("ioctl SNDCTL_DSP_SETFMT");
+ goto err;
+ }
+ if (-1 == ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize)) {
+ perror("ioctl SNDCTL_DSP_SETFMT");
+ goto err;
+ }
+ if (0 == blocksize)
+ blocksize = 4096;
+ if (rrate != rate) {
+ fprintf(stderr,"sample rate: asked for %d, hardware uses %d. ",
+ rate,rrate);
+ if (abs(rate-rrate)*100 < rate) {
+ fprintf(stderr,"that's fine (diff <1%%).\n");
+ } else {
+ fprintf(stderr,"way off, using hardware rate.\n");
+ rate = rrate;
+ }
+ }
+
+ latency = blocksize*1000/channels/rate;
+ if (afmt == AFMT_U16_BE || afmt == AFMT_S16_BE ||
+ afmt == AFMT_U16_LE || afmt == AFMT_S16_LE)
+ latency = latency/2;
+
+ stat = record ? STATUS_RECORD : STATUS_PLAYBACK;
+#if 0
+ fprintf(stderr,"%s (format=%d, %s, rate=%d, blocksize=%d, latency=%d ms)\n",
+ record ? "recording" : "playback",
+ afmt,
+ (channels == 2) ? "stereo" : "mono",
+ rate, blocksize, latency);
+#endif
+ p.channels = channels;
+ p.rate = rate;
+ p.blocksize = blocksize;
+ p.latency = latency;
+ switch (afmt) {
+ case AFMT_U8: p.format = FMT_8BIT; break;
+ case AFMT_S16_LE: p.format = FMT_16BIT; break;
+ default: fprintf(stderr,"oops(open): unsupported sound format\n"); exit(1);
+ }
+// emit newparams(&p);
+
+ if (record) {
+ trigger = ~PCM_ENABLE_INPUT;
+ ioctl(fd,SNDCTL_DSP_SETTRIGGER,&trigger);
+ trigger = PCM_ENABLE_INPUT;
+ ioctl(fd,SNDCTL_DSP_SETTRIGGER,&trigger);
+ }
+ return 0;
+
+err:
+ if (-1 != fd)
+ close(fd);
+ stat = STATUS_CLOSED;
+ fd = -1;
+ return -1;
+}
+
+void
+Soundcard::close_dev()
+{
+ close(fd);
+ fd = -1;
+ stat = STATUS_CLOSED;
+
+ return;
+}
+
+void
+Soundcard::setparams(struct SOUNDPARAMS *p)
+{
+ rate = p->rate;
+ channels = p->channels;
+ switch (p->format) {
+ case FMT_8BIT: afmt = AFMT_U8; break;
+ case FMT_16BIT: afmt = AFMT_S16_LE; break;
+ default: fprintf(stderr,"oops(set): unsupported sound format\n"); exit(1);
+ }
+
+ switch (stat) {
+ case STATUS_RECORD:
+ close_dev();
+ open_dev(TRUE);
+ break;
+ case STATUS_PLAYBACK:
+ close_dev();
+ open_dev(FALSE);
+ break;
+ case STATUS_CLOSED:
+ if (!init_done)
+ get_capabilities();
+ if (!init_done)
+ return;
+ if (0 == open_dev(TRUE))
+ close_dev();
+ break;
+ }
+
+// printf("\nformat=%d\n", p->format);
+ printf("\nchannels=%d\n", channels);
+ printf("\nrate=%d\n", rate);
+ printf("\nblocksize=%d\n", blocksize);
+ printf("\nlatency=%d\n", latency);
+
+}
+
+void
+//Soundcard::sounddata(int s)
+Soundcard::sounddata(uint8_t* buf, int &size)
+{
+ int rc,have;
+
+ switch (stat) {
+ case STATUS_RECORD:
+ /* read */
+ for (have = 0; have < blocksize;) {
+ rc = read(fd,buf+have,blocksize-have);
+ switch (rc) {
+ case -1:{
+ printf("\naudio capture failed\n");
+ size = -1;
+ return;
+ }
+ break;
+ case 0:
+ fprintf(stderr,"Huh? got 0 bytes from sound device?\n");
+ exit(1);
+ default:
+ have += rc;
+ }
+ }
+ size = have;
+// emit senddata((void*)buffer);
+ break;
+ case STATUS_PLAYBACK:
+// emit receivedata((void*)buffer);
+ if (-1 != fd)
+ write(fd,buffer,blocksize);
+// emit senddata((void*)buffer); /* fft :-) */
+ break;
+ }
+}
Added: incubator/bluesky/NCstu-2.0/src/en_de_audio.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/en_de_audio.h?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/en_de_audio.h (added)
+++ incubator/bluesky/NCstu-2.0/src/en_de_audio.h Tue Jun 3 19:48:16 2008
@@ -0,0 +1,350 @@
+//en_de_audio.h
+
+
+// RTP.
+#include "fecrtpsession.h"
+#include "en_de_sendthread.h"
+
+// Linux sys.
+#include <iostream>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <linux/types.h>
+#include <linux/videodev.h>
+#include <time.h>
+// FFmpeg
+#include <ffmpeg/avcodec.h>
+#include <ffmpeg/avformat.h>
+//#include <ffmpeg/fifo.h>
+
+
+// X11
+#include <X11/Intrinsic.h>
+#include <X11/XWDFile.h>
+
+// Jthread and JMutex
+#include <jthread.h>
+#include <jmutex.h>
+
+// Audio
+#include <linux/soundcard.h>
+
+
+//oss audio
+
+#ifndef OSS_H
+#define OSS_H
+
+/* ---------------------------------------------------------------------- */
+
+#define STATUS_CLOSED 0
+#define STATUS_RECORD 1
+#define STATUS_PLAYBACK 2
+
+
+#define FMT_UNDEFINED 0
+#define FMT_8BIT 1 /* unsigned */
+#define FMT_16BIT 2 /* signed - native byte order */
+#define FMT_MULAW 4 /* NOT SUPPORTED (yet) */
+#define FMT_ALAW 8 /* NOT SUPPORTED (yet) */
+
+#define FMT_MAX 2
+
+#define STATIC_AUDIO_FRAMES 1
+
+struct SOUNDPARAMS {
+ int format;
+ int channels;
+ int rate;
+ int blocksize;
+ int latency;
+};
+
+
+class Soundcard
+{
+
+public:
+ /* sound card capabilities */
+ char devname[32];
+ int init_done;
+ int afmt_hw;
+ int afmt_sw;
+ int channels_hw;
+
+ int trigger;
+ char driver_name[64];
+
+ /* current settings */
+ int afmt;
+ int channels;
+ int rate;
+ int blocksize;
+ int latency;
+
+ /* file handle, reference count */
+ int fd, stat;
+ char buffer[65536];
+// QSocketNotifier *telmi;
+
+ /* internal functions */
+ void get_capabilities();
+ int open_dev(int record);
+ void close_dev();
+
+public:
+ Soundcard(const char *dev);
+ ~Soundcard();
+ char *driver();
+ void setparams(struct SOUNDPARAMS *params);
+ int start_record();
+ int start_playback();
+ int kill_buffer();
+ int stop();
+
+ int has_channels(); /* # of channels (1=mono,2=stereo) */
+ int has_format(int f); /* check format availibity */
+
+//public slots:
+public:
+ void sounddata(uint8_t* buf, int &size);
+/*
+signals:
+ void senddata(void *data);
+ // !!! only one should be connected to receivedata !!!
+ void receivedata(void *data);
+ void newparams(struct SOUNDPARAMS *params);
+*/
+};
+
+#endif
+
+//oss audio
+
+#if !defined(_EN_DE_AUDIO_H__INCLUDED_)
+#define _EN_DE_AUDIO_H__INCLUDED_
+
+
+// Audio decoder.
+class CADecoder
+{
+public:
+ friend class CAudioReceiver;
+private:
+ enum ADECODERBUFSIZE {A_SDLBufSize = AVCODEC_MAX_AUDIO_FRAME_SIZE};
+ enum AUDIO_DECODEC_PARA {AUDIO_DECODE_bit_rate=64000, \
+ AUDIO_DECODE_sample_rate=AUDIO_SAMPLE_RATE,
+ A_DECODE_framerate=25, A_DECODE_frame_rate_base=1, \
+ A_DECODE_gop_size=12};
+
+public:
+ CADecoder();
+ virtual ~CADecoder();
+public:
+ int DecodeProcess(uint8_t *encodeddata_a, const int encodeddatasize_a);//,char *outbuf);
+ bool Init(enum CodecID nCodecID =CODEC_ID_MP3, int nOutBufSize =A_SDLBufSize);
+private:
+ //bool OpenAudio();
+ //void CloseAudio();
+private:
+ bool m_bInit;
+ AVCodec *m_pCodec ;
+ AVCodecContext *m_pCodecCtx ;
+ uint8_t *m_pSDLBuf;
+
+
+private:
+ //static int g_arts_count;
+// arts
+ //arts_stream_t m_stream;
+ //char m_pName[20];
+
+};
+
+// Audio encoder.
+
+class CAEncoder
+{
+ friend class CAudioSender;
+ friend class CStuAudioSender;
+private:
+ enum AUDIO_ENCODEC_PARA {AUDIO_ENCODE_bit_rate=64000, \
+ AUDIO_ENCODE_sample_rate=AUDIO_SAMPLE_RATE,
+ A_ENCODE_framerate=25, A_ENCODE_frame_rate_base=1, \
+ A_ENCODE_gop_size=12};
+private:
+ bool OpenAudio();
+ void CloseAudio();
+
+private:
+
+ enum AENCODERBUFSIZE {A_OutBufSize = 4*128*1024};//128000}; //before is 128000
+public:
+ int Capture(uint8_t** pOutBuf, int &size);
+ int EncodeProcess(uint8_t* data, uint8_t *pOutBuf[2], int nOutsize);//,BUFFERLIST pOutBuf_list);
+ bool Init(enum CodecID nCodecID =CODEC_ID_MP2);
+ CAEncoder();
+ virtual ~CAEncoder();
+ inline int encodelength(int i)
+ {
+ return m_encode_length[i];
+ }
+private:
+
+
+// for audio.
+private:
+// int m_hAudioDev;
+ uint8_t* m_data;
+ int m_datasize;
+// for encode.
+private:
+ bool m_bInit;
+// uint8_t *m_pFrameBuf;
+// AVFrame *m_pFrame;
+ AVCodec *m_pCodec ;
+ AVCodecContext *m_pCodecCtx ;
+ int m_encode_length[2];
+// audio
+// int m_hAudioDev;
+public:
+// oss
+ Soundcard m_soundcard;
+//use in encodeprocess
+
+ uint8_t* m_audio_buf;
+ FifoBuffer *m_fifo;
+};
+
+//stuaudio sender.
+class CAudioSender : private JThread
+{
+public:
+ CAudioSender();
+ ~CAudioSender();
+ bool Init(int nPort);
+ bool AddDestination(const RTPIPv4Address &des);
+ void ClearDestinations();
+ int Start(char* szFile=0, bool bIsRecord=false);
+ void Pause();
+ void Resume();
+ void Record(bool bInRecord =true);
+ void Stop();
+private:
+ //void Stop();
+ void *Thread();
+ bool stop;
+
+ JMutex stopmutex;
+
+private:
+ bool m_bIsRecord;
+ JMutex m_recordmutex;
+
+ CAEncoder m_aencoder;
+ uint8_t *m_pOutBuf[2]; //only record endcode data 2 times
+ //int m_pOutBuf_length[2]; //start from 0
+
+ FILE* m_hFile;
+ RTPSession m_fecrtpsession;
+ int m_bInit;
+ bool m_sendpause;
+ JMutex m_sendpausemutex;
+};
+
+
+
+//audio sender.
+class CStuAudioSender : private JThread
+{
+public:
+ CStuAudioSender();
+ ~CStuAudioSender();
+ bool Init(int nPort);
+ bool AddDestination(const RTPIPv4Address &des);
+ void ClearDestinations();
+ int Start(char* szFile=0, bool bIsRecord=false);
+ void Pause();
+ void Resume();
+private:
+ void Stop();
+ void *Thread();
+ bool stop;
+ JMutex stopmutex;
+private:
+// bool m_bIsRecord;
+// JMutex m_recordmutex;
+
+ CAEncoder m_aencoder;
+
+ uint8_t *m_pOutBuf[2]; //only record endcode data 2 times
+ //int m_pOutBuf_length[2]; //start from 0
+
+
+// FILE* m_hFile;
+ RTPSession m_fecrtpsession;
+ int m_bInit;
+ bool m_sendpause;
+ JMutex m_sendpausemutex;
+};
+
+
+
+
+//audio receiver
+
+class CAudioReceiver : public RTPSession
+{
+public:
+ CAudioReceiver();
+ virtual ~CAudioReceiver();
+
+ bool Init();
+ int Start(int nPort);
+ void Stop();
+
+private:
+ virtual void OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress);
+
+private:
+ bool m_bInit;
+ CADecoder m_adecoder;
+ //static CAudioWriteThread m_artswrite;
+ CAudioWriteThread m_artswrite;
+
+ char m_charNO[10];
+ int m_intNo;
+
+ int m_iloops;
+ char m_chAudioBuf[STATIC_AUDIO_FRAMES*2*4096];
+ int m_AudioBuflength;
+
+};
+
+/*
+//audio recoder.
+class CWAudioRecorder : private JThread
+{
+public:
+ CWAudioRecorder();
+ ~CWAudioRecorder();
+ int Record(char* szFile);
+ void Stop();
+private:
+ void *Thread();
+ bool stop;
+ JMutex stopmutex;
+private:
+ bool m_bPause; //for pauseing record.
+ JMutex m_pausemutex; //for pauseing record.
+ CAEncoder m_aencoder;
+ uint8_t *m_pOutBuf;
+ FILE* m_hFile;
+};
+*/
+#endif // !defined(_EN_DE_AUDIO_H__INCLUDED_)
Added: incubator/bluesky/NCstu-2.0/src/en_de_common.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/en_de_common.cpp?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/en_de_common.cpp (added)
+++ incubator/bluesky/NCstu-2.0/src/en_de_common.cpp Tue Jun 3 19:48:16 2008
@@ -0,0 +1,17 @@
+#include "en_de_common.h"
+
+static char g_error_txt[550];
+
+char* GetLastErrText()
+{
+ return g_error_txt;
+}
+
+void PErrorText(const char* error)
+{
+ if(strlen(error)<=500){
+ sprintf(g_error_txt, "\nEn_De Error:%s", error);
+ }
+}
+
+//
Propchange: incubator/bluesky/NCstu-2.0/src/en_de_common.cpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/bluesky/NCstu-2.0/src/en_de_common.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/NCstu-2.0/src/en_de_common.h?rev=662948&view=auto
==============================================================================
--- incubator/bluesky/NCstu-2.0/src/en_de_common.h (added)
+++ incubator/bluesky/NCstu-2.0/src/en_de_common.h Tue Jun 3 19:48:16 2008
@@ -0,0 +1,22 @@
+//en_de_common.h
+
+
+#if !defined(_EN_DE_COMMON_INCLUDED_)
+#define _EN_DE_COMMON_INCLUDED_
+
+extern char* GetLastErrText();
+
+
+#include "en_de_audio.h"
+#include "en_de_video.h"
+#include "en_de_screen.h"
+
+
+
+
+
+
+
+
+
+#endif // !defined(_EN_DE_COMMON_INCLUDED_)
Propchange: incubator/bluesky/NCstu-2.0/src/en_de_common.h
------------------------------------------------------------------------------
svn:executable = *