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 da...@apache.org on 2009/05/13 07:44:32 UTC
svn commit: r774247 [14/24] - in /incubator/bluesky:
tags/Bluesky_version1.0/ trunk/ trunk/sourcecode/
trunk/sourcecode/dtu_src_v1.0/ trunk/sourcecode/student_src_v1.0/
trunk/sourcecode/student_src_v1.0/pic/ trunk/sourcecode/teacher_src_1.0/
trunk/sour...
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.cc
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.cc?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.cc (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.cc Wed May 13 07:44:26 2009
@@ -0,0 +1,586 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+#include "client_communicate.h"
+#include <iostream.h>
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+
+#include "errorinfo.h"
+#include "interface.hh"
+#include "support.hh"
+
+#include "languagechoose.h"
+
+extern GtkWidget *modetech;
+extern GtkWidget *modecomu;
+
+extern GtkWidget *tech_toolbutton;
+extern GtkWidget *commu_toolbutton;
+
+extern GtkWidget *creatclass;
+extern GtkWidget *stopclass;
+
+extern GtkWidget *creat_toolbutton;
+extern GtkWidget *cancel_toolbutton;
+extern GtkWidget *allow_chat_toolbutton;
+
+extern GtkWidget *student_clist;
+
+extern GtkWidget *concentrate_add_button;
+extern GtkWidget *concentrate_concel_button;
+
+extern GtkWidget *chat_button;
+
+extern GtkTextBuffer *commu_buffer;
+extern GtkTextIter commu_end;
+
+extern GtkWidget *join_toolbutton;
+extern GtkWidget *login;
+extern GtkWidget *exitsys;
+extern GtkWidget *exit_toolbutton;
+
+extern GtkWidget *set_item;
+extern GtkWidget *set_toolbutton;
+
+
+
+extern int get_client_clist(); //define in callback.cc
+extern int is_focus_set; //0: haven't 1:set already
+extern int clist_focusid; //record focus student
+extern int allow_chat_set;//0:stop chat;1:allow chat
+
+extern int g_work_mode;
+
+extern int error_info_no; //define in callback.cc
+
+extern GtkWidget *commu_textview;
+
+gint y_position,height;
+
+//teacher connect with TServer
+
+
+JMutex client_ts_communicate::studentlist_mutex;
+
+client_ts_communicate::client_ts_communicate()
+{
+ studentlist_mutex.Init();
+ 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;
+ }
+ else
+ return 0;
+}
+
+int client_ts_communicate::establish_connect(LPCTSTR ts_IP,UINT ts_Port,UINT nSocketPort)
+{
+ 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;
+
+}
+
+int client_ts_communicate::send_mes(CRCLMSG mes,int mes_length)
+{
+
+ if( client_socket.Send(&mes,mes_length)==-1 )
+ {
+ perror("Send message failed!");
+ return -1;
+ }
+ return 0;
+}
+
+
+int client_ts_communicate::recevie_msg(char *buf,int buf_length )
+{
+ CRCLMSG * receive_str;
+ receive_str=(CRCLMSG *) buf;
+
+ switch(receive_str->rclType)
+ {
+ case 5001:
+
+ CRCLTeacherLoginR *TeacherLoginR;
+ TeacherLoginR=(CRCLTeacherLoginR *) receive_str->msg;
+
+ if(TeacherLoginR->ResponseType!=0)
+ {
+
+ error_info_no=3;
+ perror("teacher login error!");
+ gtk_widget_set_sensitive (creatclass,FALSE);
+ gtk_widget_set_sensitive(creat_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (exitsys,FALSE);
+ gtk_widget_set_sensitive(exit_toolbutton,FALSE);
+
+
+ gtk_widget_set_sensitive(set_item,TRUE);
+ gtk_widget_set_sensitive(set_toolbutton,TRUE);
+
+ gtk_widget_set_sensitive (login,TRUE);
+ gtk_widget_set_sensitive(join_toolbutton,TRUE);
+
+ return -1;
+ }
+
+ TeacherID= TeacherLoginR->TeacherID;
+ cout<<"teachloginr.ResponseType"<<" "<<TeacherLoginR->ResponseType<<endl;
+ cout<<"teachloginr.TeacherID"<<" "<<TeacherLoginR->TeacherID<<endl;
+
+ gtk_widget_set_sensitive(set_item,FALSE);
+ gtk_widget_set_sensitive(set_toolbutton,FALSE);
+
+ break;
+
+ case 10001:
+ {
+
+ CRCLCreateGroupR *CreateGroupR;
+ CreateGroupR=(CRCLCreateGroupR *) receive_str->msg;
+
+ if(CreateGroupR->ResponseType==0)
+ {
+ GroupID=CreateGroupR->GroupID;
+
+ printf("create class OK!\n");
+ }
+ else
+ {
+ error_info_no=5;
+
+ perror("creat class error!");
+ return -1;
+ }
+
+
+ printf("MCU ip is %s\n",CreateGroupR->MCUIP);
+ printf("MCU port is %d,%d\n",CreateGroupR->TVPort,CreateGroupR->TSPort);
+
+ gtk_widget_set_sensitive (stopclass,TRUE);
+ gtk_widget_set_sensitive (cancel_toolbutton,TRUE);
+
+ gtk_widget_set_sensitive (creatclass,FALSE);
+ gtk_widget_set_sensitive (creat_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (modetech, FALSE);
+ gtk_widget_set_sensitive (tech_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (modecomu, TRUE);
+ gtk_widget_set_sensitive (commu_toolbutton,TRUE);
+
+ gtk_widget_set_sensitive (chat_button, TRUE);
+ allow_chat_set=0;
+ gtk_widget_set_sensitive (allow_chat_toolbutton, TRUE);
+ allow_chat_set=0;
+
+
+
+
+
+
+ char strpath[255] = "/root/kejian/";
+
+
+ time_t now;
+
+ now = time(0);
+ tm *tnow = localtime(&now);
+ sprintf(strpath+strlen(strpath), "%d_%0.2d_%0.2d_%0.2d_%0.2d", 1900+tnow->tm_year,
+ tnow->tm_mon+1,
+ tnow->tm_mday,
+ tnow->tm_hour,
+ tnow->tm_min);
+ printf("%s\n", strpath);
+
+
+ break;
+ }
+
+
+
+ case 1031:
+ {
+
+ CRCLClientTextBroadcastR *Client_text_r;
+ Client_text_r=( CRCLClientTextBroadcastR *) receive_str->msg;
+
+
+ char text_Info[1045];
+
+ strcpy(text_Info,Client_text_r->ClientName);
+ strcat(text_Info,": ");
+ strcat(text_Info,Client_text_r->Info);
+ strcat(text_Info,"\n");
+
+ gtk_text_buffer_insert(commu_buffer,&commu_end,text_Info,-1);
+
+ flush_scrollar();
+
+ }
+ break;
+
+ case 1071:
+
+ client_ts_communicate::studentlist_mutex.Lock();
+
+ gtk_clist_freeze( GTK_CLIST(student_clist) );
+
+ CRCLTeacherGetClientListR *teacher_GetClientList;
+ teacher_GetClientList=(CRCLTeacherGetClientListR *) receive_str->msg;
+
+ int index;
+
+ char tmp[100];
+ memset(tmp,0,sizeof(tmp));
+
+ char studentInfo[1024][3][limitbit];
+ char *ptr_studentInfo[1024][3];
+ memset(studentInfo,0,sizeof(studentInfo));
+ memset(ptr_studentInfo,0,sizeof(ptr_studentInfo));
+
+ char avmode[15];
+ char no_avmode[16];
+ memset(avmode,0,sizeof(avmode));
+ memset(no_avmode,0,sizeof(no_avmode));
+
+ strcpy(avmode,pYES);
+ strcpy(no_avmode,pNO);
+ if(teacher_GetClientList->ResponseType==0)
+ {
+
+ gtk_clist_clear(GTK_CLIST(student_clist));
+
+ for(index=0;index<teacher_GetClientList->ClientNum;index++)
+ {
+ printf("get STUID %d\n",teacher_GetClientList->ClientList[index].ClientID);
+ printf(" student name is %s ,AVMOde is %d\n",teacher_GetClientList->ClientList[index].ClientName,teacher_GetClientList->ClientList[index].IsFocus);
+
+ sprintf(tmp, "%d",teacher_GetClientList->ClientList[index].ClientID);
+
+ memcpy(studentInfo[index][0],tmp,strlen(tmp));
+ ptr_studentInfo[index][0]=studentInfo[index][0];
+
+
+ memcpy(studentInfo[index][1],teacher_GetClientList->ClientList[index].ClientName,strlen(teacher_GetClientList->ClientList[index].ClientName));
+ ptr_studentInfo[index][1]=studentInfo[index][1];
+
+ if(teacher_GetClientList->ClientList[index].IsFocus==0){
+
+ memcpy(studentInfo[index][2],avmode,strlen(avmode));
+ ptr_studentInfo[index][2]=studentInfo[index][2];
+ }
+
+ else if(teacher_GetClientList->ClientList[index].IsFocus==1){
+
+ memcpy(studentInfo[index][2],no_avmode,strlen(no_avmode));
+ ptr_studentInfo[index][2]=studentInfo[index][2];
+ }
+
+
+ gtk_clist_append(GTK_CLIST(student_clist),ptr_studentInfo[index]);
+
+ }
+ }
+
+
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+
+ client_ts_communicate::studentlist_mutex.Unlock();
+ printf("\n1071 finished!!!!!!!!\n");
+ break;
+
+ case 1012:
+ {
+
+ CRCLClientApplyFocusRToTM *client_apply_focus;
+ client_apply_focus= (CRCLClientApplyFocusRToTM *)receive_str->msg;
+
+
+
+ char text_Info[1045];
+
+ strcpy(text_Info,ptext);
+
+
+ char tmp[10];
+ sprintf(tmp,"%d",client_apply_focus->FocusClientID);
+ strcat(text_Info,tmp);
+
+ strcat(text_Info,"\n\n");
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer,&commu_end,text_Info,-1);
+ textview_mutex.Unlock();
+
+ flush_scrollar();
+
+
+ }
+ break;
+
+ case 1022:
+ {
+
+ CRCLClientDestroyFocusRToTM *client_destroy_focus;
+ client_destroy_focus= (CRCLClientDestroyFocusRToTM *)receive_str->msg;
+
+
+
+ char text_Info[1045];
+
+ strcpy(text_Info,ptext01);
+
+
+ char tmp[10];
+ sprintf(tmp,"%d",client_destroy_focus->FocusClientID);
+ strcat(text_Info,tmp);
+ strcat(text_Info,"\n\n");
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer,&commu_end,text_Info,-1);
+ textview_mutex.Unlock();
+
+ flush_scrollar();
+ }
+ break;
+
+ case 10022:
+ {
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze( GTK_CLIST(student_clist) );
+
+ CRCLClientJoinInGroupRAll *client_join_group_response;
+ client_join_group_response=(CRCLClientJoinInGroupRAll *) receive_str->msg;
+
+ char *add_student[3];
+ char comm_mode[5];
+ char no_comm_mode[6];
+ char temp[10];
+
+ strcpy(comm_mode,pYES);
+ strcpy(no_comm_mode,pNO);
+
+ sprintf(temp, "%d",client_join_group_response->ClientInfo.ClientID);
+ add_student[0]=temp;
+
+ add_student[1]=client_join_group_response->ClientInfo.ClientName;
+
+ if(client_join_group_response->ClientInfo.IsFocus==0)
+ add_student[2]=comm_mode;
+
+ else if(client_join_group_response->ClientInfo.IsFocus==1)
+ add_student[2]=no_comm_mode;
+
+
+ gtk_clist_append(GTK_CLIST(student_clist), add_student);
+
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+ break;
+ }
+ case 1051:
+
+ CRCLTeacherAllowClientFocusR *allow_client_response;
+ allow_client_response=(CRCLTeacherAllowClientFocusR *) receive_str->msg;
+
+ if(allow_client_response->ResponseType!=0)
+ {
+ error_info_no=10;
+
+ perror("failed to set focus!");
+ return -1;
+ }
+
+
+ if(get_client_clist()<0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+
+ is_focus_set=1;
+
+ gtk_widget_set_sensitive (concentrate_concel_button, TRUE);
+ break;
+
+ case 1061:
+
+ CRCLTeacherCancelClientFocusR *cancel_client_response;
+ cancel_client_response=(CRCLTeacherCancelClientFocusR *) receive_str->msg;
+
+ printf("cancel client focus response is %d\n",cancel_client_response->ResponseType);
+ if(cancel_client_response->ResponseType!=0)
+ {
+ error_info_no=12;
+
+ perror("failed to cancel focus!");
+
+ return -1;
+ }
+
+ if(is_focus_set==1){
+
+
+ if(get_client_clist()<0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+
+ is_focus_set=0;
+ }
+ break;
+
+ case 10032:
+
+ CRCLClientLeaveGroupRAll *client_leave_group_response;
+ client_leave_group_response=(CRCLClientLeaveGroupRAll *) receive_str->msg;
+
+ if(client_leave_group_response->ClientInfo.ClientID==clist_focusid)
+ {
+ if(is_focus_set==1)
+ is_focus_set=0;
+ gtk_widget_set_sensitive (concentrate_concel_button, FALSE);
+
+ }
+
+
+ if(get_client_clist()<0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+
+ break;
+
+ case 10042:
+
+ CRCLMCULeaveGroupRAll *mcu_leave_group;
+ mcu_leave_group=(CRCLMCULeaveGroupRAll *) receive_str->msg;
+
+
+
+ is_focus_set=0;
+
+ gtk_widget_set_sensitive (creatclass,TRUE);
+ gtk_widget_set_sensitive (creat_toolbutton,TRUE);
+
+ gtk_widget_set_sensitive (stopclass,FALSE);
+ gtk_widget_set_sensitive (cancel_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (modetech, FALSE);
+ gtk_widget_set_sensitive (tech_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (modecomu, FALSE);
+ gtk_widget_set_sensitive (commu_toolbutton,FALSE);
+
+ gtk_widget_set_sensitive (chat_button, FALSE);
+
+ break;
+ case 1091:
+
+ struct CRCLTeacherIfAllowChatR *allow_chat_response;
+ allow_chat_response=(CRCLTeacherIfAllowChatR *) receive_str->msg;
+ if(allow_chat_response->ResponseType!=0)
+ {
+
+ if(allow_chat_set==0)
+ {
+ error_info_no=19;
+ gtk_tool_button_set_label((GtkToolButton*)allow_chat_toolbutton,pmodeswich);
+
+ }
+ else
+ { error_info_no=20;
+ gtk_tool_button_set_label((GtkToolButton*)allow_chat_toolbutton,palwcht);
+
+ }
+ perror("failed to set chat!");
+ return -1;
+ }
+ if(allow_chat_set==0)
+ {
+ allow_chat_set=1;
+
+ }
+
+ else
+ {
+ allow_chat_set=0;
+
+ }
+ break;
+ default:
+
+ break;
+ }
+
+ return 0;
+
+}
+
+void client_ts_communicate::get_text_from_msg(char *Message)
+{
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer,&commu_end,Message,-1);
+ textview_mutex.Unlock();
+}
+
+void client_ts_communicate::flush_scrollar()
+{
+ textview_mutex.Lock();
+ error_info_no=40;
+ textview_mutex.Unlock();
+}
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.h?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.h (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/client_communicate.h Wed May 13 07:44:26 2009
@@ -0,0 +1,63 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+#ifndef CLIENT_COMMUNICATE_H
+#define CLIENT_COMMUNICATE_H
+#include <list>
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "singlecomm.h"
+#include "trcclient.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);
+ int close_socket(int nHow);
+ void get_text_from_msg(char *Message);
+ void flush_scrollar();
+ DWORD TeacherID;
+ DWORD GroupID;
+
+ static JMutex studentlist_mutex;
+ private:
+ CClientSocket client_socket;
+ CSingleComm client_socket_thread;
+ JMutex textview_mutex;
+};
+
+
+
+
+
+#endif
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.cpp?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.cpp (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.cpp Wed May 13 07:44:26 2009
@@ -0,0 +1,146 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+// 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()
+
+{
+
+ unsigned long len;
+
+ if(m_lEvent == 0)
+
+ return;
+
+ IOCtl(FIONREAD, &len);
+
+ if(len==0){
+
+ Close();
+
+ printf("\nA client disconnected.");
+
+ return ;
+
+ }
+
+
+
+
+
+
+ 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 ;
+
+}
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.h?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.h (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/clientsocket.h Wed May 13 07:44:26 2009
@@ -0,0 +1,39 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+// 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)
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.cpp?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.cpp (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.cpp Wed May 13 07:44:26 2009
@@ -0,0 +1,484 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+#include "en_de_sendthread.h"
+
+
+
+
+
+extern void PErrorText(const char* error);
+
+//CSendThread class.
+
+//////////////////////////////////////////////////////////////////////
+
+// Construction/Destruction
+
+//////////////////////////////////////////////////////////////////////
+
+CSendThread::CSendThread(int nSendBufSize)
+
+{
+
+ stop = false;
+
+ m_bInit = 0;
+
+
+
+ if(nSendBufSize <=2){
+
+ m_nSendBufSize = 2;
+
+ }
+
+ else
+
+ if(nSendBufSize>=25){
+
+ m_nSendBufSize = 25;
+
+ }
+
+ else
+
+ m_nSendBufSize = nSendBufSize;
+
+
+
+#if (defined(WIN32) || defined(_WIN32_WCE))
+
+ timeinit.Dummy();
+
+#endif // WIN32 || _WIN32_WCE
+
+}
+
+
+
+CSendThread::~CSendThread()
+
+{
+
+
+ Stop();
+
+
+
+}
+
+
+
+#define MAX_PACKET_SIZE 10*1024
+
+bool CSendThread::Init(int nPort)
+
+{
+
+ if(m_bInit)
+
+ return true;
+
+
+
+ RTPSessionParams sessParams1;
+
+ sessParams1.SetOwnTimestampUnit(1.0 / 30.0);
+
+ sessParams1.SetUsePollThread(0);
+ sessParams1.SetMaximumPacketSize(MAX_PACKET_SIZE);
+
+ RTPUDPv4TransmissionParams transParams1;
+
+ transParams1.SetPortbase(nPort);
+
+ int status1 = m_fecrtpsession.Create(sessParams1, &transParams1);
+
+ if (status1){
+
+
+ return false;
+
+ }
+
+
+
+
+ m_fecrtpsession.SetDefaultMark(true);
+
+ m_fecrtpsession.SetDefaultPayloadType(1);
+
+ m_fecrtpsession.SetDefaultTimestampIncrement(0);
+
+
+
+
+
+ m_bInit = true;
+
+ return m_bInit;
+
+}
+
+
+
+
+
+
+
+int CSendThread::Start()
+
+{
+
+ if(!m_bInit)
+
+ return -1;
+
+
+
+ if (JThread::IsRunning())
+
+ return 0;
+
+
+
+ if (!stopmutex.IsInitialized())
+
+ {
+
+ if (stopmutex.Init() < 0)
+
+ return -2;
+
+ }
+
+
+
+ stop = false;
+
+
+
+ if (!m_senddatamutex.IsInitialized())
+
+ {
+
+ if (m_senddatamutex.Init() < 0)
+
+ return -2;
+
+ }
+
+
+
+ if (JThread::Start() < 0){
+
+ return -6;
+
+ }
+
+
+
+ return 0;
+
+}
+
+
+
+void CSendThread::Stop()
+
+{
+
+ if (!IsRunning())
+
+ return;
+
+
+
+ stopmutex.Lock();
+
+ stop = true;
+
+ stopmutex.Unlock();
+
+
+
+ sleep(1);
+
+ if (JThread::IsRunning())
+
+ {
+
+#ifndef _WIN32_WCE
+
+ std::cerr << "RTPPollThread: Warning! Having to kill thread!" << std::endl;
+
+#endif // _WIN32_WCE
+
+ JThread::Kill();
+
+ }
+
+ stop = false;
+
+
+
+
+
+}
+
+
+
+int CSendThread::SendData(uint8_t *data, int datalen)
+
+{
+
+ SENDBUFDATA *pData;
+
+
+ if(!m_bInit)
+
+ return -1;
+
+
+
+ pData = new SENDBUFDATA;
+
+ if(pData==0){
+
+
+ return -2;
+
+ }
+
+
+
+ pData->data = new uint8_t[datalen];
+
+ if(pData->data==0){
+
+ delete pData;
+
+
+ return -3;
+
+ }
+
+
+
+ memcpy(pData->data, data, datalen);
+
+ pData->datalen = datalen;
+
+
+
+
+
+ m_senddatamutex.Lock();
+
+ m_senddata.insert(m_senddata.end(), pData);
+
+ m_senddatamutex.Unlock();
+
+
+
+ return 0;
+
+}
+
+
+
+
+
+void *CSendThread::Thread()
+
+{
+
+ JThread::ThreadStarted();
+
+
+
+
+ SENDBUFDATA *senddata = new SENDBUFDATA[m_nSendBufSize];
+
+ bool stopthread;
+
+
+
+ stopmutex.Lock();
+
+ stopthread = stop;
+
+ stopmutex.Unlock();
+
+
+
+ int size;
+
+ SENDBUFDATA* p;
+
+ SendDatalist::iterator itera;
+
+ int index;
+
+ while (!stopthread)
+
+ {
+
+
+
+ m_senddatamutex.Lock();
+
+ size = m_senddata.size();
+
+ if(size==0){
+
+ m_senddatamutex.Unlock();
+
+
+
+ usleep(50000);
+
+
+
+ stopmutex.Lock();
+
+ stopthread = stop;
+
+ stopmutex.Unlock();
+
+ continue;
+
+ }
+
+ if(size>m_nSendBufSize){
+
+ for(itera=m_senddata.begin(); itera!=m_senddata.end(); itera++){
+
+ p = *itera;
+
+ delete p->data;
+
+ delete p;
+
+ p = 0;
+
+ }
+
+ m_senddata.clear();
+
+ size = 0;
+
+ }
+
+ else{
+
+ for(itera=m_senddata.begin(),index=0; itera!=m_senddata.end(); itera++,index++){
+
+ p = *itera;
+
+ senddata[index].data = p->data;
+
+ senddata[index].datalen = p->datalen;
+
+ delete p;
+
+ p = 0;
+
+ }
+
+ m_senddata.clear();
+
+ size = index;
+
+ }
+
+
+
+ m_senddatamutex.Unlock();
+
+
+
+ for(index=0; index<size; index++){
+
+ m_fecrtpsession.SendFECPacket(senddata[index].data, senddata[index].datalen, 5000);
+
+ delete senddata[index].data;
+
+ }
+
+
+
+
+
+ stopmutex.Lock();
+
+ stopthread = stop;
+
+ stopmutex.Unlock();
+
+
+
+ }
+
+ printf("\nSendthread stoped.\n");
+
+ return 0;
+
+}
+
+
+
+bool CSendThread::AddDestination(const RTPIPv4Address &des)
+
+{
+
+ if(!m_bInit)
+
+ return false;
+
+ if(m_fecrtpsession.AddDestination(des)<0)
+
+ return false;
+
+
+
+ return true;
+
+}
+
+
+
+void CSendThread::ClearDestinations()
+
+{
+
+ if(!m_bInit)
+
+ return ;
+
+ m_fecrtpsession.ClearDestinations();
+
+}
+
+
+
+
+
+
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.h?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.h (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/en_de_sendthread.h Wed May 13 07:44:26 2009
@@ -0,0 +1,88 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+
+
+// rtp
+#include "fecrtpsession.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>
+
+// SDL
+#include <time.h>
+
+// X11
+#include <X11/Intrinsic.h>
+#include <X11/XWDFile.h>
+// Jthread and JMutex
+#include <jthread.h>
+#include <jmutex.h>
+
+#if !defined(_EN_DE_SENDTHREAD_H__INCLUDED_)
+#define _EN_DE_SENDTHREAD_H__INCLUDED_
+
+#define AUDIO_SAMPLE_RATE 44100
+#define STATIC_AUDIO_CHANNLE 1
+
+
+
+struct SENDBUFDATA{
+ uint8_t* data;
+ int datalen;
+};
+typedef std::list<SENDBUFDATA*> SendDatalist;
+
+//CSendThread class.
+class CSendThread : private JThread
+{
+public:
+ CSendThread(int nSendBufSize);
+ ~CSendThread();
+ bool Init(int nPort);
+ bool AddDestination(const RTPIPv4Address &des);
+ void ClearDestinations();
+ int SendData(uint8_t *data, int datalen);
+ int Start();
+ void Stop();
+private:
+ void *Thread();
+ bool stop;
+ JMutex stopmutex;
+private:
+ CFECRtpSession m_fecrtpsession;
+ int m_bInit;
+
+ int m_nSendBufSize;
+ SendDatalist m_senddata;
+ JMutex m_senddatamutex;
+};
+
+
+
+
+#endif // !defined(_EN_DE_SENDTHREAD_H__INCLUDED_)
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/error.txt
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/error.txt?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/error.txt (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/error.txt Wed May 13 07:44:26 2009
@@ -0,0 +1,26 @@
+(ncteacher:10693): Gdk-CRITICAL **: gdk_drawable_get_colormap: assertion `GDK_IS_DRAWABLE (drawable)' failed
+
+(ncteacher:10693): Gdk-CRITICAL **: gdk_drawable_get_depth: assertion `GDK_IS_DRAWABLE (drawable)' failed
+
+(ncteacher:10693): Gdk-WARNING **: Using Xft rendering requires the drawable argument to
+have a specified colormap. All windows have a colormap,
+however, pixmaps only have colormap by default if they
+were created with a non-NULL window argument. Otherwise
+a colormap must be set on them with gdk_drawable_set_colormap
+
+
+The program 'ncteacher' received an X Window System error.
+This probably reflects a bug in the program.
+The error was 'RenderBadPicture (invalid Picture parameter)'.
+ (Details: serial 127571 error_code 180 request_code 154 minor_code 23)
+ (Note to programmers: normally, X errors are reported asynchronously;
+ that is, you will receive the error a while after causing it.
+ To debug your program, run it with the --sync command line
+ option to change this behavior. You can then get a meaningful
+ backtrace from your debugger if you break on the gdk_x_error() function.)
+
+
+Xlib: unexpected async reply (sequence 0xf544)
+
+lib: unexpected async reply (sequence 0x2983c)!
+
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/errorinfo.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/errorinfo.h?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/errorinfo.h (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/errorinfo.h Wed May 13 07:44:26 2009
@@ -0,0 +1,250 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+#include "languagechoose.h"
+
+
+#ifndef _ERRORINFO_H
+#define _ERRORINFO_H
+
+
+
+
+#ifdef LANGUAGE_EN
+#define ERROR001 "Error 001:The establishment of server and classroom socket connection failure!\n\n"
+#define ERROR_S001 "Information 001: Please check server's IP is correct and confirm the server has been activated!"
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR001 "é误001:ä¸è¯¾å æå¡ä¸å¿å»ºç«socketè¿æ¥å¤±è´¥!\n\n"
+#define ERROR_S001 "æç¤º001:è¯·æ£æ¥è¯¾å æå¡ä¸å¿IPå°åï¼è¯·ç¡®è®¤è¯¾å æå¡ä¸å¿å·²å¯å¨"
+#endif
+
+
+#ifdef LANGUAGE_EN
+#define ERROR002 "Error 002:The establishment of service centers and classroom socket connection failure!\n\n"
+#define ERROR_S002 "Information 002:Please check the server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR002 "é误002:ä¸è¯¾å æå¡ä¸å¿å»ºç«socketè¿æ¥å¤±è´¥!\n\n"
+#define ERROR_S002 "æç¤º002:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR003 "Error 003:Medium-Login failed!\n\n"
+#define ERROR_S003 "Information 003:Please check server's status, inspection user's name and password."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR003 "é误003:æè¯¾ç«¯ç»å½å¤±è´¥ï¼\n\n"
+#define ERROR_S003 "æç¤º003:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ,æ£æ¥ç»å½ç¨æ·ååå¯ç "
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR004 "Error 004:Send message to create class failure!\n\n"
+#define ERROR_S004 "Information 004:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR004 "é误004:åéåå»ºè¯¾å æ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S004 "æç¤º004:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR005 "Error 005:The creation of classroom failure!\n\n"
+#define ERROR_S005 "Information 005:Please check server's status, and make sure that the DTU has been activated."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR005 "é误005:å建课å 失败ï¼\n\n"
+#define ERROR_S005 "æç¤º005:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æï¼è¯·ç¡®ä¿å·²å¯å¨ä¸»DTU"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR006 "Error 006:Send message to cancele creating class error!\n\n"
+#define ERROR_S006 "Information 006:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR006 "é误006:åéåæ¶å建课å 失败ï¼\n\n"
+#define ERROR_S006 "æç¤º006:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR007 "Error 007:Send message to get Students List error!\n\n"
+#define ERROR_S007 "Information 007:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR007 "é误007:åéè·åå¦çåè¡¨æ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S007 "æç¤º007:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR008 "Error 008:Send message to get Students List error!\n\n"
+#define ERROR_S008 "Information 008:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR008 "é误008:åéè·åå¦çåè¡¨æ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S008 "æç¤º008:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR009 "Error 009:Send message to student error!\n\n"
+#define ERROR_S009 "Information 009:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR009 "é误009:åéæå®ç¦ç¹å¦çæ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S009 "æç¤º009:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR010 "Error 010:Designated focus of students fail!\n\n"
+#define ERROR_S010 "Information 010:Please check server's status and make sure that the user is still online."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR010 "é误010:æå®ç¦ç¹å¦ç失败ï¼\n\n"
+#define ERROR_S010 "æç¤º010:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æï¼è¯·ç¡®è®¤è¯¥ç¨æ·ä»ç¶ç»å½"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR011 "Error 011:Send message to cancel the focus of the student error!\n\n"
+#define ERROR_S011 "Information 011:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR011 "é误011:åéåæ¶ç¦ç¹å¦çæ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S011 "æç¤º011:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR012 "Error 012: Cancel the student's focus error!\n\n"
+#define ERROR_S012 "Information 012:Please check server's status, and make sure that the user do not logout."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR012 "é误012:åæ¶ç¦ç¹å¦ç失败ï¼\n\n"
+#define ERROR_S012 "æç¤º012:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æï¼è¯·ç¡®è®¤è¯¥ç¨æ·æ²¡æéåº"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR013 "Error 013:Send message to chat failure!\n\n"
+#define ERROR_S013 "Information 013:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR013 "é误013:åéèå¤©æ¶æ¯å¤±è´¥ï¼\n\n"
+#define ERROR_S013 "æç¤º013:è¯·æ£æ¥è¯¾å æå¡ä¸å¿ç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR014 "Error 014:Data reception port write error!\n\n"
+#define ERROR_S014 "Information 014:Focus of students receiving audio data ports please fill in even-numbered."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR014 "é误014:æ°æ®æ¥æ¶ç«¯å£å¡«åé误ï¼\n\n"
+#define ERROR_S014 "æç¤º014:æ¥æ¶ç¦ç¹å¦çé³é¢æ°æ®ç«¯å£è¯·å¡«åå¶æ°"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR015 "Error 015:Data reception port write error!\n\n"
+#define ERROR_S015 "Information 015:Focus of students receiving audio data ports please fill in even-numbered."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR015 "é误015:æ°æ®æ¥æ¶ç«¯å£å¡«åé误ï¼\n\n"
+#define ERROR_S015 "æç¤º015:æ¥æ¶ç¦ç¹å¦çè§é¢æ°æ®ç«¯å£è¯·å¡«åå¶æ°"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR016 "Error 016:Data reception port write error!\n\n"
+#define ERROR_S016 "Information 016:Focus of students receiving audio data ports please fill in even-numbered."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR016 "é误016:æ¥æ¶æ°æ®ç«¯å£å¡«åé误ï¼\n\n"
+#define ERROR_S016 "æç¤º016:ä¸¤è·¯æ°æ®ç«¯å£è¯·å¡«åä¸åå¼"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR017 "Error 017:The class's name filling in is error!\n\n"
+#define ERROR_S017 "Information 017:Please check whether you fill in the class's name, and whether the name is too long."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR017 "é误017:课å åå¡«åé误ï¼\n\n"
+#define ERROR_S017 "æç¤º017:è¯·æ£æ¥è¯¾å 忝å¦å¡«å,以ååç§°æ¯å¦è¿é¿"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR018 "Error 018:Username filled is error!\n\n"
+#define ERROR_S018 "Information 018:Please check whether you fill in username, and whether the name is too long."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR018 "é误018:ç¨æ·åå¡«åé误ï¼\n\n"
+#define ERROR_S018 "æç¤º018:è¯·æ£æ¥ç¨æ·åæ¯å¦å¡«å,以ååç§°æ¯å¦è¿é¿"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR019 "Error 019:Prohibiting chatting failure!\n\n"
+#define ERROR_S019 "Information 019:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR019 "é误019ï¼ç¦æ¢è天失败ï¼\n\n"
+#define ERROR_S019 "æç¤º019ï¼è¯·æ£æ¥è¯¾å æå¡ä¸å¿çç¶æ"
+#endif
+
+
+//
+#ifdef LANGUAGE_EN
+#define ERROR020 "Error 020:Failure to allow chatting!\n\n"
+#define ERROR_S020 "Information 020:Please check server's status."
+#endif
+#ifdef LANGUAGE_CH
+#define ERROR020 "é误020ï¼å
许è天失败! \n\n"
+#define ERROR_S020 "æç¤º020ï¼è¯·æ£æ¥è¯¾å æå¡ä¸å¿çç¶æ"
+#endif
+
+
+
+
+
+
+#endif
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.cpp?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.cpp (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.cpp Wed May 13 07:44:26 2009
@@ -0,0 +1,2946 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+// fecrtpsession.cpp: implementation of the CFECRtpSession class.
+
+//////////////////////////////////////////////////////////////////////
+
+
+
+#include <unistd.h>
+
+#include "fecrtpsession.h"
+
+
+
+#ifndef GF_BITS
+
+#define GF_BITS 8
+
+#endif
+
+
+
+#define u_char unsigned char
+
+#define u_short unsigned short
+
+#define u_long unsigned long
+
+
+
+#define bcmp(a,b,n) memcmp(a,b,n)
+
+#define bcopy(s, d, siz) memcpy((d), (s), (siz))
+
+#define bzero(d, siz) memset((d), '\0', (siz))
+
+
+
+
+
+
+
+#define DEB(x)
+
+#define DDB(x) x
+
+
+
+#if (GF_BITS < 2 && GF_BITS >16)
+
+#error "GF_BITS must be 2 .. 16"
+
+#endif
+
+
+
+#if (GF_BITS <= 8)
+
+typedef unsigned char gf;
+
+#else
+
+typedef unsigned short gf;
+
+#endif
+
+
+
+#define GF_SIZE ((1 << GF_BITS) - 1) /* powers of \alpha */
+
+
+
+static char *allPp[] = { /* GF_BITS polynomial */
+
+ 0, /* 0 no code */
+
+ 0, /* 1 no code */
+
+ "111", /* 2 1+x+x^2 */
+
+ "1101", /* 3 1+x+x^3 */
+
+ "11001", /* 4 1+x+x^4 */
+
+ "101001", /* 5 1+x^2+x^5 */
+
+ "1100001", /* 6 1+x+x^6 */
+
+ "10010001", /* 7 1 + x^3 + x^7 */
+
+ "101110001", /* 8 1+x^2+x^3+x^4+x^8 */
+
+ "1000100001", /* 9 1+x^4+x^9 */
+
+ "10010000001", /* 10 1+x^3+x^10 */
+
+ "101000000001", /* 11 1+x^2+x^11 */
+
+ "1100101000001", /* 12 1+x+x^4+x^6+x^12 */
+
+ "11011000000001", /* 13 1+x+x^3+x^4+x^13 */
+
+ "110000100010001", /* 14 1+x+x^6+x^10+x^14 */
+
+ "1100000000000001", /* 15 1+x+x^15 */
+
+ "11010000000010001" /* 16 1+x+x^3+x^12+x^16 */
+
+};
+
+
+
+
+
+static gf gf_exp[2*GF_SIZE]; /* index->poly form conversion table */
+
+static int gf_log[GF_SIZE + 1]; /* Poly->index form conversion table */
+
+static gf inverse[GF_SIZE+1]; /* inverse of field elem. */
+
+
+
+int modnn(int x)
+
+{
+
+ while (x >= GF_SIZE)
+
+ {
+
+ x -= GF_SIZE;
+
+ x = (x >> GF_BITS) + (x & GF_SIZE);
+
+ }
+
+ return x;
+
+}
+
+
+
+#define SWAP(a,b,t) {t tmp; tmp=a; a=b; b=tmp;}
+
+
+
+
+
+#if (GF_BITS <= 8)
+
+static gf gf_mul_table[GF_SIZE + 1][GF_SIZE + 1];
+
+
+
+#define gf_mul(x,y) gf_mul_table[x][y]
+
+
+
+#define USE_GF_MULC register gf * __gf_mulc_
+
+#define GF_MULC0(c) __gf_mulc_ = gf_mul_table[c]
+
+#define GF_ADDMULC(dst, x) dst ^= __gf_mulc_[x]
+
+
+
+static void init_mul_table()
+
+{
+
+ int i, j;
+
+ for (i=0; i< GF_SIZE+1; i++)
+
+ for (j=0; j< GF_SIZE+1; j++)
+
+ gf_mul_table[i][j] = gf_exp[modnn(gf_log[i] + gf_log[j]) ] ;
+
+
+
+ for (j=0; j< GF_SIZE+1; j++)
+
+ gf_mul_table[0][j] = gf_mul_table[j][0] = 0;
+
+}
+
+#else
+
+static inline gf gf_mul(gf x,gf y)
+
+{
+
+ if ( (x) == 0 || (y)==0 ) return 0;
+
+
+
+ return gf_exp[gf_log[x] + gf_log[y] ] ;
+
+}
+
+#define init_mul_table()
+
+
+
+#define USE_GF_MULC register gf * __gf_mulc_
+
+#define GF_MULC0(c) __gf_mulc_ = &gf_exp[ gf_log[c] ]
+
+#define GF_ADDMULC(dst, x) { if (x) dst ^= __gf_mulc_[ gf_log[x] ] ; }
+
+#endif
+
+
+
+
+
+static void* my_malloc(int sz, char *err_string)
+
+{
+
+ void *p = malloc( sz );
+
+ if (p == 0) {
+
+ }
+
+ return p ;
+
+}
+
+
+
+#define NEW_GF_MATRIX(rows, cols) (gf *)my_malloc(rows * cols * sizeof(gf), " ## __LINE__ ## " )
+
+
+
+
+
+static void generate_gf(void)
+
+{
+
+ int i;
+
+ gf mask;
+
+ char *Pp = allPp[GF_BITS] ;
+
+
+
+ mask = 1;
+
+ gf_exp[GF_BITS] = 0;
+
+
+
+ for (i = 0; i < GF_BITS; i++, mask <<= 1 )
+
+ {
+
+ gf_exp[i] = mask;
+
+ gf_log[gf_exp[i]] = i;
+
+ if ( Pp[i] == '1' )
+
+ gf_exp[GF_BITS] ^= mask;
+
+ }
+
+ gf_log[gf_exp[GF_BITS]] = GF_BITS;
+
+
+
+ mask = 1 << (GF_BITS - 1 ) ;
+
+ for (i = GF_BITS + 1; i < GF_SIZE; i++)
+
+ {
+
+ if (gf_exp[i - 1] >= mask)
+
+ gf_exp[i] = gf_exp[GF_BITS] ^ ((gf_exp[i - 1] ^ mask) << 1);
+
+ else
+
+ gf_exp[i] = gf_exp[i - 1] << 1;
+
+ gf_log[gf_exp[i]] = i;
+
+ }
+
+
+
+ gf_log[0] = GF_SIZE ;
+
+
+
+ for (i = 0 ; i < GF_SIZE ; i++)
+
+ gf_exp[i + GF_SIZE] = gf_exp[i] ;
+
+
+
+
+
+ inverse[0] = 0 ;
+
+ inverse[1] = 1;
+
+ for (i=2; i<=GF_SIZE; i++)
+
+ inverse[i] = gf_exp[GF_SIZE-gf_log[i]];
+
+}
+
+
+
+
+
+#define addmul(dst, src, c, sz) \
+ if (c != 0) addmul1(dst, src, c, sz)
+
+
+
+#define UNROLL 16
+
+static void addmul1(gf *dst1, gf *src1, gf c, int sz)
+
+{
+
+ USE_GF_MULC ;
+
+ register gf *dst = dst1, *src = src1 ;
+
+ gf *lim = &dst[sz - UNROLL + 1] ;
+
+
+
+ GF_MULC0(c) ;
+
+
+
+#if (UNROLL > 1)
+
+ for (; dst < lim ; dst += UNROLL, src += UNROLL )
+
+ {
+
+ GF_ADDMULC( dst[0] , src[0] );
+
+ GF_ADDMULC( dst[1] , src[1] );
+
+ GF_ADDMULC( dst[2] , src[2] );
+
+ GF_ADDMULC( dst[3] , src[3] );
+
+ #if (UNROLL > 4)
+
+ GF_ADDMULC( dst[4] , src[4] );
+
+ GF_ADDMULC( dst[5] , src[5] );
+
+ GF_ADDMULC( dst[6] , src[6] );
+
+ GF_ADDMULC( dst[7] , src[7] );
+
+ #endif
+
+ #if (UNROLL > 8)
+
+ GF_ADDMULC( dst[8] , src[8] );
+
+ GF_ADDMULC( dst[9] , src[9] );
+
+ GF_ADDMULC( dst[10] , src[10] );
+
+ GF_ADDMULC( dst[11] , src[11] );
+
+ GF_ADDMULC( dst[12] , src[12] );
+
+ GF_ADDMULC( dst[13] , src[13] );
+
+ GF_ADDMULC( dst[14] , src[14] );
+
+ GF_ADDMULC( dst[15] , src[15] );
+
+ #endif
+
+ }
+
+#endif
+
+ lim += UNROLL - 1 ;
+
+ for (; dst < lim; dst++, src++ )
+
+ GF_ADDMULC( *dst , *src );
+
+}
+
+
+
+
+static void matmul(gf *a, gf *b, gf *c, int n, int k, int m)
+
+{
+
+ int row, col, i ;
+
+
+
+ for (row = 0; row < n ; row++)
+
+ {
+
+ for (col = 0; col < m ; col++)
+
+ {
+
+ gf *pa = &a[ row * k ];
+
+ gf *pb = &b[ col ];
+
+ gf acc = 0 ;
+
+ for (i = 0; i < k ; i++, pa++, pb += m )
+
+ acc ^= gf_mul( *pa, *pb ) ;
+
+ c[ row * m + col ] = acc ;
+
+ }
+
+ }
+
+}
+
+
+
+#ifdef DEBUG
+
+static int is_identity(gf *m, int k)
+
+{
+
+ int row, col ;
+
+ for (row=0; row<k; row++)
+
+ for (col=0; col<k; col++)
+
+ if ( (row==col && *m != 1) || (row!=col && *m != 0) )
+
+ return 0 ;
+
+ else
+
+ m++ ;
+
+ return 1 ;
+
+}
+
+#endif
+
+
+
+
+
+DEB( int pivloops=0; int pivswaps=0 ; )
+
+static int invert_mat(gf *src, int k)
+
+{
+
+ gf c, *p ;
+
+ int irow, icol, row, col, i, ix ;
+
+
+
+ int error = 1 ;
+
+ int *indxc = (int *)my_malloc(k*sizeof(int), "indxc");
+
+
+
+ int *indxr = (int *)my_malloc(k*sizeof(int), "indxr");
+
+ int *ipiv = (int *)my_malloc(k*sizeof(int), "ipiv");
+
+ gf *id_row = NEW_GF_MATRIX(1, k);
+
+ gf *temp_row = NEW_GF_MATRIX(1, k);
+
+
+
+ if ((indxc==0)||(indxr==0)||(id_row==0)||(temp_row==0)||(ipiv==0))
+
+ {
+
+ goto fail;
+
+ }
+
+
+
+ bzero(id_row, k*sizeof(gf));
+
+ DEB( pivloops=0; pivswaps=0 ; )
+
+
+
+ for (i = 0; i < k ; i++)
+
+ ipiv[i] = 0 ;
+
+
+
+ for (col = 0; col < k ; col++) {
+
+ gf *pivot_row ;
+
+
+
+ irow = icol = -1 ;
+
+ if (ipiv[col] != 1 && src[col*k + col] != 0)
+
+ {
+
+ irow = col ;
+
+ icol = col ;
+
+ goto found_piv ;
+
+ }
+
+ for (row = 0 ; row < k ; row++)
+
+ {
+
+ if (ipiv[row] != 1)
+
+ {
+
+ for (ix = 0 ; ix < k ; ix++)
+
+ {
+
+ DEB( pivloops++ ; )
+
+ if (ipiv[ix] == 0)
+
+ {
+
+ if (src[row*k + ix] != 0)
+
+ {
+
+ irow = row ;
+
+ icol = ix ;
+
+ goto found_piv ;
+
+ }
+
+ } else if (ipiv[ix] > 1)
+
+ {
+
+ goto fail ;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ if (icol == -1)
+
+ {
+
+
+ goto fail ;
+
+ }
+
+ found_piv:
+
+ ++(ipiv[icol]) ;
+
+
+
+ if (irow != icol)
+
+ {
+
+ for (ix = 0 ; ix < k ; ix++ )
+
+ {
+
+ SWAP( src[irow*k + ix], src[icol*k + ix], gf) ;
+
+ }
+
+ }
+
+ indxr[col] = irow ;
+
+ indxc[col] = icol ;
+
+ pivot_row = &src[icol*k] ;
+
+ c = pivot_row[icol] ;
+
+ if (c == 0)
+
+ {
+
+
+ goto fail ;
+
+ }
+
+ if (c != 1 )
+
+ {
+
+ DEB( pivswaps++ ; )
+
+ c = inverse[ c ] ;
+
+ pivot_row[icol] = 1 ;
+
+ for (ix = 0 ; ix < k ; ix++ )
+
+ pivot_row[ix] = gf_mul(c, pivot_row[ix] );
+
+ }
+
+ id_row[icol] = 1;
+
+ if (bcmp(pivot_row, id_row, k*sizeof(gf)) != 0)
+
+ {
+
+ for (p = src, ix = 0 ; ix < k ; ix++, p += k )
+
+ {
+
+ if (ix != icol)
+
+ {
+
+ c = p[icol] ;
+
+ p[icol] = 0 ;
+
+ addmul(p, pivot_row, c, k );
+
+ }
+
+ }
+
+ }
+
+ id_row[icol] = 0;
+
+ }
+ for (col = k-1 ; col >= 0 ; col-- )
+
+ {
+
+ if (indxr[col] <0 || indxr[col] >= k)
+
+ {
+
+ goto fail;
+
+
+ }
+
+ else if (indxc[col] <0 || indxc[col] >= k)
+
+ {
+
+ goto fail;
+
+
+ }
+
+ else if (indxr[col] != indxc[col] )
+
+ {
+
+ for (row = 0 ; row < k ; row++ )
+
+ {
+
+ SWAP( src[row*k + indxr[col]], src[row*k + indxc[col]], gf) ;
+
+ }
+
+ }
+
+ }
+
+
+
+ error = 0 ;
+
+fail:
+
+ if (indxc!=0)
+
+ free(indxc);
+
+ if (indxr!=0)
+
+ free(indxr);
+
+ if (ipiv!=0)
+
+ free(ipiv);
+
+ if (id_row!=0)
+
+ free(id_row);
+
+ if (temp_row!=0)
+
+ free(temp_row);
+
+ return error ;
+
+}
+
+
+
+int invert_vdm(gf *src, int k)
+
+{
+
+ int i, j, row, col ;
+
+ gf *b, *c, *p;
+
+ gf t, xx ;
+
+
+
+ if (k == 1)
+
+ return 0 ;
+
+
+
+ c = NEW_GF_MATRIX(1, k);
+
+
+
+ b = NEW_GF_MATRIX(1, k);
+
+
+
+ p = NEW_GF_MATRIX(1, k);
+
+ if ( (c==0)||(b==0)||(p==0))
+
+ {
+
+ if (b==0)
+
+ free(b);
+
+ if (c==0)
+
+ free(c);
+
+ if (p==0)
+
+ free(p);
+
+ return 1;
+
+ }
+
+
+
+ for ( j=1, i = 0 ; i < k ; i++, j+=k )
+
+ {
+
+ c[i] = 0 ;
+
+ p[i] = src[j] ;
+ }
+
+ c[k-1] = p[0] ;
+
+ for (i = 1 ; i < k ; i++ ) {
+
+ gf p_i = p[i] ;
+
+ for (j = k-1 - ( i - 1 ) ; j < k-1 ; j++ )
+
+ c[j] ^= gf_mul( p_i, c[j+1] ) ;
+
+ c[k-1] ^= p_i ;
+
+ }
+
+
+
+ for (row = 0 ; row < k ; row++ ) {
+
+
+
+ xx = p[row] ;
+
+ t = 1 ;
+
+ b[k-1] = 1 ;
+
+ for (i = k-2 ; i >= 0 ; i-- ) {
+
+ b[i] = c[i+1] ^ gf_mul(xx, b[i+1]) ;
+
+ t = gf_mul(xx, t) ^ b[i] ;
+
+ }
+
+ for (col = 0 ; col < k ; col++ )
+
+ src[col*k + row] = gf_mul(inverse[t], b[col] );
+
+ }
+
+ free(c) ;
+
+ free(b) ;
+
+ free(p) ;
+
+ return 0 ;
+
+}
+
+
+
+static int fec_initialized = 0 ;
+
+static void init_fec()
+
+{
+
+
+
+ generate_gf();
+
+
+
+ init_mul_table();
+
+
+
+ fec_initialized = 1 ;
+
+}
+
+
+
+
+
+#define FEC_MAGIC 0xFECC0DEC
+
+
+
+struct fec_parms {
+
+ u_long magic ;
+
+ int k, n ;
+
+ gf *enc_matrix ;
+
+} ;
+
+
+
+void fec_free(struct fec_parms *p)
+
+{
+
+ if (p==0 ||
+
+ p->magic != ( ( (FEC_MAGIC ^ p->k) ^ p->n) ^ (int)(p->enc_matrix)) )
+
+ {
+
+
+ return ;
+
+ }
+
+ free(p->enc_matrix);
+
+ free(p);
+
+}
+
+
+
+
+
+struct fec_parms * fec_new(int k, int n)
+
+{
+
+ int row, col ;
+
+ gf *p, *tmp_m ;
+
+
+
+ struct fec_parms *retval ;
+
+
+
+ if (fec_initialized == 0)
+
+ init_fec();
+
+
+
+
+
+
+
+ if (k > GF_SIZE + 1 || n > GF_SIZE + 1 || k > n ) {
+
+ return 0 ;
+
+ }
+
+
+
+ retval = (struct fec_parms*)my_malloc(sizeof(struct fec_parms), "new_code");
+
+ if (retval==0)
+
+ return 0;
+
+
+
+ retval->k = k ;
+
+ retval->n = n ;
+
+ retval->enc_matrix = NEW_GF_MATRIX(n, k);
+
+ if (retval->enc_matrix==0)
+
+ {
+
+ free(retval);
+
+ return 0;
+
+ }
+
+
+
+ retval->magic = ( ( FEC_MAGIC ^ k) ^ n) ^ (int)(retval->enc_matrix) ;
+
+ tmp_m = NEW_GF_MATRIX(n, k);
+
+ if (tmp_m==0)
+
+ {
+
+ free(retval->enc_matrix);
+
+ free(retval);
+
+ return 0;
+
+ }
+
+
+
+
+
+ tmp_m[0] = 1 ;
+
+ for (col = 1; col < k ; col++)
+
+ tmp_m[col] = 0 ;
+
+ for (p = tmp_m + k, row = 0; row < n-1 ; row++, p += k) {
+
+ for ( col = 0 ; col < k ; col ++ )
+
+ p[col] = gf_exp[modnn(row*col)];
+
+ }
+
+
+
+ if (invert_vdm(tmp_m, k))
+
+ {
+
+ free(retval->enc_matrix);
+
+ free(retval);
+
+ free(tmp_m);
+
+ return 0;
+
+ }
+
+ matmul(tmp_m + k*k, tmp_m, retval->enc_matrix + k*k, n - k, k, k);
+
+
+
+ bzero(retval->enc_matrix, k*k*sizeof(gf) );
+
+ for (p = retval->enc_matrix, col = 0 ; col < k ; col++, p += k+1 )
+
+ *p = 1 ;
+
+ free(tmp_m);
+
+
+
+ DEB(pr_matrix(retval->enc_matrix, n, k, "encoding_matrix");)
+
+ return retval ;
+
+}
+
+
+
+
+
+void fec_encode(struct fec_parms *code, gf *src[], gf *fec, int index, int sz)
+
+{
+
+ int i, k = code->k ;
+
+ gf *p ;
+
+
+
+ if (GF_BITS > 8)
+
+ sz /= 2 ;
+
+
+
+ if (index < k)
+
+ bcopy(src[index], fec, sz*sizeof(gf) ) ;
+
+ else if (index < code->n) {
+
+ p = &(code->enc_matrix[index*k] );
+
+ bzero(fec, sz*sizeof(gf));
+
+ for (i = 0; i < k ; i++)
+
+ addmul(fec, src[i], p[i], sz ) ;
+
+ } else
+
+ ;
+
+
+
+}
+
+
+
+
+
+static int shuffle(gf *pkt[], int index[], int k)
+
+{
+
+ int i;
+
+
+
+ for ( i = 0 ; i < k ; ) {
+
+ if (index[i] >= k || index[i] == i)
+
+ i++ ;
+
+ else {
+
+ int c = index[i] ;
+
+
+
+ if (index[c] == c) {
+
+ return 1 ;
+
+ }
+
+ SWAP(index[i], index[c], int) ;
+
+ SWAP(pkt[i], pkt[c], gf *) ;
+
+ }
+
+ }
+
+ DEB(
+
+ for ( i = 0 ; i < k ; i++ ) {
+
+ if (index[i] < k && index[i] != i) {
+
+ return 1 ;
+
+ }
+
+ }
+
+ )
+
+ return 0 ;
+
+}
+
+
+
+static gf* build_decode_matrix(struct fec_parms *code, gf *pkt[], int index[])
+
+{
+
+ int i , k = code->k ;
+
+ gf *p, *matrix = NEW_GF_MATRIX(k, k);
+
+
+
+ if (matrix==0)
+
+ {
+
+ return 0;
+
+ }
+
+ for (i = 0, p = matrix ; i < k ; i++, p += k )
+
+ {
+
+ if (index[i] < k)
+
+ {
+
+ bzero(p, k*sizeof(gf) );
+
+ p[i] = 1 ;
+
+ } else
+
+ if (index[i] < code->n )
+
+ bcopy( &(code->enc_matrix[index[i]*k]), p, k*sizeof(gf) );
+
+ else
+
+ {
+
+ free(matrix) ;
+
+ return 0 ;
+
+ }
+
+ }
+
+
+
+ if (invert_mat(matrix, k)) {
+
+ free(matrix);
+
+ matrix = 0 ;
+
+ }
+
+ return matrix ;
+
+}
+
+
+
+int fec_decode(struct fec_parms *code, gf *pkt[], int index[], int sz)
+
+{
+
+ gf *m_dec ;
+
+ gf **new_pkt ;
+
+ int i,row, col , k = code->k ;
+
+
+
+ if (GF_BITS > 8)
+
+ sz /= 2 ;
+
+
+
+ if (shuffle(pkt, index, k))
+
+ return 1 ;
+
+ m_dec = build_decode_matrix(code, pkt, index);
+
+
+
+ if (m_dec == 0)
+
+ return 1 ;
+
+
+
+ new_pkt = (gf **)my_malloc (k * sizeof (gf * ), "new pkt pointers" );
+
+ if (new_pkt==0)
+
+ {
+
+ free(m_dec);
+
+ return 1;
+
+ }
+
+ for (row = 0 ; row < k ; row++ ) {
+
+ if (index[row] >= k) {
+
+ new_pkt[row] = (gf *)my_malloc (sz * sizeof (gf), "new pkt buffer" );
+
+ if (new_pkt[row]==0)
+
+ {
+
+ free(m_dec);
+
+ for (i=0;i<row;i++)
+
+ {
+
+ free(new_pkt[row]);
+
+ }
+
+ free(new_pkt);
+
+ return 1;
+
+ }
+
+ bzero(new_pkt[row], sz * sizeof(gf) ) ;
+
+ for (col = 0 ; col < k ; col++ )
+
+ addmul(new_pkt[row], pkt[col], m_dec[row*k + col], sz) ;
+
+ }
+
+ }
+
+
+
+ for (row = 0 ; row < k ; row++ ) {
+
+ if (index[row] >= k) {
+
+ bcopy(new_pkt[row], pkt[row], sz*sizeof(gf));
+
+ free(new_pkt[row]);
+
+ }
+
+ }
+
+ free(new_pkt);
+
+ free(m_dec);
+
+ return 0;
+
+}
+
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////
+
+// Construction/Destruction
+
+//////////////////////////////////////////////////////////////////////
+
+
+
+CFECRtpSession::CFECRtpSession()
+
+{
+
+
+
+
+ m_nRedundentRate = 1;
+
+ m_nFrameNo = 0;
+
+
+
+
+
+ m_oldVideotimestamp = 0;
+
+ m_usLatestVideoSeq = 0;
+
+
+
+ int i;
+
+ for(i=0; i<FECLISTSIZE; i++){
+
+ m_FECListInfo[i].b_isEmpty=true;
+
+ m_FECListInfo[i].ul_HaveArriveNum=0;
+
+ m_FECListInfo[i].ul_timestamp=0;
+
+ m_FECListInfo[i].ul_TotalNeedNum=0;
+
+ }
+
+
+
+}
+
+
+
+CFECRtpSession::~CFECRtpSession()
+
+{
+
+
+
+}
+
+
+
+
+
+void CFECRtpSession::OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
+
+{
+
+ FECHEADER* fec_header;
+
+ unsigned char *RecvData;
+
+ RecvData = pack->GetPayloadData();
+
+ fec_header = (FECHEADER*)RecvData;
+
+ int Datalen = pack->GetPayloadLength();
+
+
+ int rtptimestamp = pack->GetTimestamp();
+
+ int rtpFramNo = pack->GetExtensionID();
+
+
+
+ if(m_oldVideotimestamp!=0 || m_usLatestVideoSeq!=0){
+
+ if(rtptimestamp<=m_oldVideotimestamp && rtpFramNo<=m_usLatestVideoSeq){
+
+ if(m_usLatestVideoSeq-rtpFramNo<=10 && m_oldVideotimestamp-rtptimestamp<=10)
+
+ return ;
+
+
+
+ }
+
+ m_usLatestVideoSeq = 0;
+
+ m_oldVideotimestamp = 0;
+
+ }
+
+
+
+
+
+ if(fec_header->FecCoded==0){
+
+
+
+ int nVideoframeNum;
+
+ bool bIsSameVideoUDP=false;
+
+ nVideoframeNum = m_PreSendFrameList.size();
+
+
+
+
+
+
+ if(bIsSameVideoUDP==false)
+
+ {
+
+ unsigned char* pPacket;
+
+ pPacket = new unsigned char[Datalen];
+
+ if (pPacket==NULL)
+
+ {
+
+ return;
+
+ }
+
+
+
+ memcpy(pPacket,RecvData,Datalen);
+
+
+
+ FRAMEINFO* pFrameInfo = NULL;
+
+ pFrameInfo = new FRAMEINFO;
+
+
+
+ if (pFrameInfo==NULL)
+
+ {
+
+ delete pPacket;
+
+ return;
+
+ }
+
+
+
+ pFrameInfo->FECCoded = false;
+
+ pFrameInfo->ul_timestamp = rtptimestamp;
+
+ pFrameInfo->us_latestseq = rtpFramNo;
+
+ pFrameInfo->l_datalen = Datalen-sizeof(FECHEADER);
+
+ pFrameInfo->pData = pPacket+sizeof(FECHEADER);
+
+
+ m_PreSendFrameList.insert(m_PreSendFrameList.end(), pFrameInfo);
+
+
+ UpdateFrames();
+
+
+
+ }
+
+ }
+
+ else{
+
+ if(fec_header->FecCoded==1)
+
+ {
+
+
+
+ FRAMEINFO* pFrameInfo;
+
+ FRAMEINFOLIST::iterator itera;
+
+ for(itera=m_PreSendFrameList.begin(); itera != m_PreSendFrameList.end(); ++itera){
+
+ pFrameInfo = *itera;
+
+ if(rtptimestamp==pFrameInfo->ul_timestamp)
+
+ return;
+
+ }
+
+
+
+
+
+ int i;
+
+ bool b_isNotAdd = true;
+
+
+
+ for( i=0;i<FECLISTSIZE;i++)
+
+ {
+
+ if(m_VideoDataList[i].size()!=0)
+
+ {
+
+
+
+
+
+ if(rtptimestamp==m_FECListInfo[i].ul_timestamp)
+
+ {
+
+ b_isNotAdd = false;
+
+
+
+
+ bool bIsSameFECVideoData = false;
+
+
+
+ if(bIsSameFECVideoData==false)
+
+ {
+
+ unsigned char *pPack = new unsigned char[Datalen];
+
+ if (pPack==NULL)
+
+ {
+
+ return;
+
+ }
+
+ memcpy(pPack,RecvData,Datalen);
+
+
+
+ m_VideoDataList[i].insert(m_VideoDataList[i].end(), (char*)pPack);
+
+
+
+
+
+
+
+ m_FECListInfo[i].ul_HaveArriveNum++;
+
+
+
+
+
+ if(m_FECListInfo[i].ul_HaveArriveNum == m_FECListInfo[i].ul_TotalNeedNum)
+
+ {
+
+
+
+ if (FECDecode(&(m_FECListInfo[i]),&m_VideoDataList[i], pack) == 0)
+
+ {
+
+ UpdateFrames();
+
+
+
+ }
+
+ else
+
+ {
+
+ printf("\nFEC decode failed.");
+
+
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ if(b_isNotAdd)
+
+ {
+
+
+
+
+
+ for(i=0;i<FECLISTSIZE;i++)
+
+ {
+
+
+
+ if(m_FECListInfo[i].b_isEmpty)
+
+ {
+
+
+ unsigned char *pPack = new unsigned char[Datalen];
+
+ if (pPack==NULL)
+
+ {
+
+ return;
+
+ }
+
+ memcpy(pPack,RecvData,Datalen);
+
+
+ m_VideoDataList[i].insert(m_VideoDataList[i].end(), (char*)pPack);
+
+
+
+ m_FECListInfo[i].b_isEmpty = false;
+
+ m_FECListInfo[i].ul_HaveArriveNum = 1;
+
+ m_FECListInfo[i].ul_timestamp = rtptimestamp;
+
+
+ m_FECListInfo[i].ul_TotalNeedNum = fec_header->OriginalK;
+
+ b_isNotAdd = false;
+
+ return;
+
+ }
+
+ }
+
+ }
+
+ if(b_isNotAdd)
+
+ {
+
+
+
+
+ ulong time=m_FECListInfo[0].ul_timestamp;
+
+ int j=0;
+
+
+
+
+ for(i=1;i<FECLISTSIZE;i++)
+
+ {
+
+ if(m_FECListInfo[i].ul_timestamp<time)
+
+ {
+
+ time = m_FECListInfo[i].ul_timestamp;
+
+ j = i;
+
+ }
+
+ }
+
+
+
+
+ char* p;
+
+ FECDATALIST::iterator itera;
+
+ for(itera=m_VideoDataList[j].begin(); itera != m_VideoDataList[j].end(); ++itera){
+
+ p = *itera;
+
+ delete p;
+
+ p=0;
+
+ }
+
+ m_VideoDataList[j].clear();
+
+
+
+
+
+
+
+
+ unsigned char *pPack = new unsigned char[Datalen];
+
+ if (pPack==NULL)
+
+ {
+
+ return;
+
+ }
+
+ memcpy(pPack,RecvData,Datalen);
+
+
+ m_VideoDataList[j].insert(m_VideoDataList[j].end(), (char*)pPack);
+
+
+
+ m_FECListInfo[j].b_isEmpty = false;
+
+ m_FECListInfo[j].ul_HaveArriveNum = 1;
+
+ m_FECListInfo[j].ul_timestamp = rtptimestamp;
+
+ m_FECListInfo[j].ul_TotalNeedNum = fec_header->OriginalK;
+
+ return;
+
+ }
+
+ }
+
+ }
+
+
+
+
+
+
+
+ return;
+
+
+
+}
+
+
+
+int CFECRtpSession::FECDecode(FECLISTINFO* pFecListInfo,FECDATALIST *pFecDataList, RTPPacket *pack)
+
+{
+
+ int PSize;
+
+ int *ixs;
+
+ void *code;
+
+ unsigned char* *d_src;
+
+
+
+ unsigned char * pDataBuf;
+
+ ulong ul_timestamp;
+
+
+ unsigned int kCount;
+
+ kCount = pFecListInfo->ul_TotalNeedNum;
+
+
+
+ FECHEADER* fec_header;
+
+ unsigned char *RecvData;
+
+ RecvData = pack->GetPayloadData();
+
+ fec_header = (FECHEADER*)RecvData;
+
+
+ int rtptimestamp = pack->GetTimestamp();
+
+ int rtpFramNo = pack->GetExtensionID();
+
+
+
+
+
+ ul_timestamp = rtptimestamp;
+
+
+
+
+
+
+
+ PSize = fec_header->PacketSize;
+
+
+
+ code = (*fec_new)(fec_header->OriginalK, fec_header->RedunN);
+
+ if (code==NULL)
+
+ {
+
+ return 1;
+
+ }
+
+ ixs = new int[kCount];
+
+ if (ixs==NULL)
+
+ {
+
+ fec_free((struct fec_parms *)code);
+
+ return 1;
+
+ }
+
+ d_src = new PUCHAR[kCount];
+
+ if (d_src==NULL)
+
+ {
+
+ delete ixs;
+
+ fec_free((struct fec_parms *)code);
+
+ return 1;
+
+ }
+
+ long OriginalDataLen;
+
+ unsigned int j;
+
+ for(j=0;j<kCount;j++)
+
+ {
+
+ d_src[j] = new unsigned char[PSize];
+
+ if (d_src[j]==NULL)
+
+ {
+
+ delete ixs;
+
+ fec_free((struct fec_parms *)code);
+
+ for (unsigned int ii=0;ii<j;ii++)
+
+ {
+
+ delete d_src[ii];
+
+ }
+
+ delete d_src;
+
+ return 1;
+
+ }
+
+ }
+
+ char* p;
+
+ FECDATALIST::iterator itera;
+
+ for(j=0, itera=pFecDataList->begin(); j<kCount && itera != pFecDataList->end(); j++, itera++){
+
+ FECHEADER* fec_header1;
+
+ p = *itera;
+
+ fec_header1 = (FECHEADER*)(p);
+
+
+ ixs[j] = fec_header1->OrigiCol;
+
+ memcpy(d_src[j],(char*)(p+sizeof(FECHEADER)),fec_header1->PacketSize);
+
+ delete p;
+
+ }
+
+
+
+ pFecDataList->clear();
+
+
+
+ pFecListInfo->b_isEmpty=true;
+
+ pFecListInfo->ul_HaveArriveNum=0;
+
+ pFecListInfo->ul_timestamp=0;
+
+ pFecListInfo->ul_TotalNeedNum=0;
+
+
+
+ int CodeResult = 0;
+
+ try
+
+ {
+
+ CodeResult = fec_decode((struct fec_parms *)code,(unsigned char **)d_src, ixs, PSize);
+
+ }
+
+ catch(...)
+
+ {
+
+ CodeResult = 1;
+
+ }
+
+
+
+ if (CodeResult==0)
+
+ {
+
+
+
+ OriginalDataLen = GetDataLen(d_src,PSize,kCount);
+
+ pDataBuf = new unsigned char[OriginalDataLen];
+
+ if (pDataBuf!=NULL)
+
+ {
+
+ GetData(pDataBuf,d_src,PSize,kCount);
+
+
+
+ FRAMEINFO *pFrameInfo;
+
+ pFrameInfo = new FRAMEINFO;
+
+ if (pFrameInfo!=NULL)
+
+ {
+
+ pFrameInfo->FECCoded = true;
+
+ pFrameInfo->ul_timestamp = ul_timestamp;
+
+ pFrameInfo->us_latestseq = rtpFramNo;
+
+ pFrameInfo->l_datalen = OriginalDataLen;
+
+ pFrameInfo->pData = pDataBuf;
+
+
+
+ m_PreSendFrameList.insert(m_PreSendFrameList.end(), pFrameInfo);
+
+ }
+
+ }
+
+
+
+
+
+ }
+
+
+
+ delete ixs;
+
+ for(unsigned int i=0;i<kCount;i++)
+
+ {
+
+ delete d_src[i];
+
+ }
+
+ delete d_src;
+
+ fec_free((struct fec_parms *)code);
+
+
+
+ return CodeResult;
+
+
+
+}
+
+
+
+long CFECRtpSession::GetDataLen(PUCHAR* d_src,long lPacketSize,unsigned int kCount)
+
+{
+
+
+ PADHEADER* pad_header;
+
+ long OriginalDataLen=0;
+
+
+
+ for(unsigned int i=0;i<kCount;i++)
+
+ {
+
+
+
+ pad_header = (PADHEADER*)(d_src[i]);
+
+ if(pad_header->paddled==0)
+
+ {
+
+ OriginalDataLen = OriginalDataLen+lPacketSize-sizeof(PADHEADER);
+
+ }
+
+ else if(pad_header->paddled==1)
+
+ {
+
+ OriginalDataLen = OriginalDataLen+lPacketSize-sizeof(PADHEADER)-pad_header->padlen;
+
+ }
+
+ }
+
+ return OriginalDataLen;
+
+}
+
+
+
+void CFECRtpSession::GetData(unsigned char* pData,PUCHAR* d_src,long lPacketSize,unsigned int kCount)
+
+{
+
+ unsigned char* midbuf;
+
+ midbuf = pData;
+
+ PADHEADER* pad_header;
+
+ for(unsigned int i=0;i<kCount;i++)
+
+ {
+
+
+
+ pad_header = (PADHEADER*)(d_src[i]);
+
+ if(pad_header->paddled==0)
+
+ {
+
+ memcpy(midbuf,d_src[i]+sizeof(PADHEADER),lPacketSize-sizeof(PADHEADER));
+
+ midbuf = midbuf+lPacketSize-sizeof(PADHEADER);
+
+ }
+
+ else if(pad_header->paddled==1)
+
+ {
+
+ memcpy(midbuf,d_src[i]+sizeof(PADHEADER),lPacketSize-sizeof(PADHEADER)-pad_header->padlen);
+
+ midbuf = midbuf+lPacketSize-sizeof(PADHEADER)-pad_header->padlen;
+
+ }
+
+ }
+
+
+
+}
+
+
+
+int CFECRtpSession::GetRtpMaxLen()
+
+{
+
+
+
+ return RtpMaxLen;
+
+}
+
+
+
+
+
+int CFECRtpSession::SendFECPacket(void *lpData, int datalen, int ndelay )
+
+{
+
+ int nRtpMaxLen;
+
+ char *pFECPacket;
+
+ FECHEADER* fec_header;
+
+
+
+ pFECPacket = 0;
+
+ nRtpMaxLen = GetRtpMaxLen();
+
+
+
+ IncrementTimestamp(1);
+
+ SetDefaultTimestampIncrement(0);
+
+ m_nFrameNo++;
+
+ if(datalen+sizeof(FECHEADER) <= nRtpMaxLen){
+
+ pFECPacket = new char[datalen+sizeof(FECHEADER)];
+
+ if(pFECPacket == 0){
+
+ return -1;
+
+ }
+
+ fec_header = (FECHEADER*)pFECPacket;
+
+ fec_header->FecCoded = 0;
+
+ memcpy(pFECPacket+sizeof(FECHEADER),lpData,datalen);
+
+
+
+
+ SendPacketEx(pFECPacket, datalen+sizeof(FECHEADER), m_nFrameNo, 0, 0);
+
+ delete[] pFECPacket;
+
+ usleep(ndelay);
+
+ return 0;
+
+ }
+
+
+
+ FECEncodeSend(lpData, datalen, m_nFrameNo, ndelay);
+
+ return 0;
+
+}
+
+
+
+
+
+
+
+int CFECRtpSession::FECEncodeSend(void *pData,
+
+ long datalen,
+
+ unsigned int FrameNo,
+
+ int ndelay )
+
+{
+
+ int SZ;
+
+ void *code =0;
+
+ int kk ;
+
+ uchar* SendData=0;
+
+ FECHEADER* fec_header;
+
+ PADHEADER* pad_header;
+
+ int lim = GF_SIZE + 1;
+
+ int *ixs = 0 ;
+
+ int redudant,i;
+
+ int lastpacketlen;
+
+ uchar **d_original, **d_src;
+
+
+
+
+
+
+
+ bool CodeResult = true;
+
+
+
+
+
+ SZ = GetRtpMaxLen();
+
+ try
+
+ {
+
+ kk = datalen/(SZ-sizeof(PADHEADER));
+
+ }
+
+ catch(...)
+
+ {
+
+ return -1;
+
+ }
+
+ if(kk<0)
+
+ return -1;
+
+ lastpacketlen = datalen%(SZ-sizeof(PADHEADER));
+
+ if (lastpacketlen!=0)
+
+ kk++;
+
+
+
+ d_original = (uchar**)malloc(kk * sizeof(void *));
+
+ if (d_original==0)
+
+ return -2;
+
+
+
+ d_src = (uchar**)malloc(kk * sizeof(void *));
+
+ if ((d_original==0)||(d_src==0))
+
+ {
+
+ free(d_original);
+
+ return -3;
+
+ }
+
+ for (i=0;i<kk;i++)
+
+ {
+
+ d_original[i] = 0;
+
+ d_src[i] = 0;
+
+ }
+
+
+
+ for (i=0; i<kk; i++)
+
+ {
+
+ d_original[i] = (uchar*)malloc(SZ);
+
+ if (d_original[i]==0)
+
+ goto fail;
+
+ d_src[i] = (uchar*)malloc(SZ);
+
+ if (d_src[i]==0)
+
+ goto fail;
+
+ }
+
+
+
+ code = (*fec_new)(kk, lim);
+
+ if (code==0)
+
+ {
+
+ goto fail;
+
+ }
+
+
+
+ ixs = (int*)malloc(kk * sizeof(int));
+
+ if (ixs==0)
+
+ goto fail;
+
+
+
+ SendData = (uchar*)malloc(SZ+sizeof(FECHEADER));
+
+ if (SendData==0)
+
+ goto fail;
+
+
+
+ for (i=0; i<kk; i++) ixs[i] = kk+i;
+
+
+
+
+
+ for (i=0;i<kk;i++)
+
+ {
+
+ pad_header = (PADHEADER*)d_original[i];
+
+ if ((i!=(kk-1))||(lastpacketlen==0))
+
+ {
+
+ pad_header->paddled = UNPAD;
+
+ pad_header->padlen = 0;
+
+
+
+ memcpy(d_original[i]+sizeof(PADHEADER),(uchar*)pData+i*(SZ-sizeof(PADHEADER)),SZ-sizeof(PADHEADER));
+
+ }
+
+ else
+
+ {
+
+ pad_header->paddled = ISPAD;
+
+ pad_header->padlen = SZ-sizeof(PADHEADER)-lastpacketlen;
+
+ memcpy(d_original[i]+sizeof(PADHEADER),(uchar*)pData+i*(SZ-sizeof(PADHEADER)),lastpacketlen);
+
+ memset(d_original[i]+sizeof(PADHEADER)+lastpacketlen, 'A', SZ-sizeof(PADHEADER)-lastpacketlen);
+
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+ int maxpacket;
+
+
+
+ if(m_nRedundentRate<=0)
+
+ {
+
+
+
+ maxpacket = 0;
+
+ }
+
+ else if(m_nRedundentRate > 200)
+
+ {
+
+
+
+ maxpacket = 0;
+
+ }
+
+ else if(m_nRedundentRate > 100)
+
+ {
+
+
+
+
+
+ maxpacket = (int)((m_nRedundentRate - 100)*kk/100) + 1;
+
+
+
+ if(maxpacket > kk)
+
+ {
+
+ maxpacket = kk;
+
+ }
+
+
+
+ if(maxpacket > MAXFECPACKET - kk)
+
+ {
+
+ maxpacket = MAXFECPACKET - kk;
+
+ }
+
+ }
+
+ else
+
+ {
+
+
+
+
+
+ if(kk < 5)
+
+ {
+
+ maxpacket = kk;
+
+
+
+ if(maxpacket > MAXFECPACKET - kk)
+
+ {
+
+ maxpacket = MAXFECPACKET - kk;
+
+ }
+
+ }
+
+ else
+
+ {
+
+
+
+ maxpacket = (int)(m_nRedundentRate*kk/100) + 5;
+
+
+
+ if(maxpacket > kk)
+
+ {
+
+ maxpacket = kk;
+
+ }
+
+
+
+ if(maxpacket > MAXFECPACKET - kk)
+
+ {
+
+ maxpacket = MAXFECPACKET - kk;
+
+ }
+
+ }
+
+ }
+
+
+
+
+
+
+
+
+ for( i = 0 ; i < maxpacket ; i++ )
+
+ {
+
+ try
+
+ {
+
+ fec_encode((fec_parms *)code, (unsigned char**)d_original, (unsigned char*)(d_src[i]), ixs[i], SZ );
+
+ }
+
+ catch(...)
+
+ {
+
+ CodeResult = false;
+
+ }
+
+ }
+
+
+
+ if (CodeResult==false)
+
+ goto fail;
+
+
+
+
+
+
+
+ redudant = 0;
+
+
+
+
+
+ if ( (redudant!=-1))
+
+ {
+
+ for(i=0;i<kk;i++)
+
+ {
+
+ memset(SendData, 0, SZ+sizeof(FECHEADER));
+
+ fec_header = (FECHEADER*)SendData;
+
+ fec_header->FecCoded = FECCODED;
+
+ fec_header->OriginalK = kk;
+
+ fec_header->OrigiCol = i;
+
+ fec_header->PacketSize = SZ;
+
+ fec_header->RedunN = lim;
+
+ memcpy(SendData+sizeof(FECHEADER),d_original[i],SZ);
+
+
+
+ SendPacketEx(SendData,SZ+sizeof(FECHEADER), FrameNo, 0, 0);
+
+ usleep(ndelay);
+
+ }
+
+ }
+
+
+
+ if ( kk>20 )
+
+ {
+
+ if ( redudant==-1)
+
+ {
+
+ redudant = 1;
+
+ }else if (kk>20)
+
+ {
+
+ redudant=+5;
+
+ }
+
+ }
+
+
+
+ if (redudant>=kk)
+
+ {
+
+ redudant = kk;
+
+ }
+
+
+
+ if (kk+redudant>=MAXFECPACKET)
+
+ redudant = MAXFECPACKET-kk;
+
+
+
+
+
+ for(i=0;i<maxpacket;i++)
+
+ {
+
+
+
+ memset(SendData, 0, SZ+sizeof(FECHEADER));
+
+ fec_header = (FECHEADER*)SendData;
+
+ fec_header->FecCoded = FECCODED;
+
+ fec_header->OriginalK = kk;
+
+ fec_header->OrigiCol = kk+i;
+
+ fec_header->PacketSize = SZ;
+
+ fec_header->RedunN = lim;
+
+ memcpy(SendData+sizeof(FECHEADER),d_src[i],SZ);
+
+
+
+ SendPacketEx(SendData,SZ+sizeof(FECHEADER), FrameNo, 0, 0);
+
+ usleep(ndelay);
+
+ }
+
+
+
+
+
+ if (SendData!=0)
+
+ free(SendData);
+
+ if (code!=0)
+
+ fec_free((fec_parms *)code);
+
+ for (i=0; i<kk; i++)
+
+ {
+
+ free(d_original[i]);
+
+ free(d_src[i]);
+
+ }
+
+ free(d_original);
+
+ free(d_src);
+
+ free(ixs);
+
+
+ return 0;
+
+fail:
+
+ if (SendData!=0)
+
+ free(SendData);
+
+ if (code!=0)
+
+ fec_free((fec_parms *)code);
+
+ for (i=0; i<kk; i++)
+
+ {
+
+ if (d_original[i]!=0)
+
+ free(d_original[i]);
+
+ if (d_src[i]!=0)
+
+ free(d_src[i]);
+
+ }
+
+ if (d_original!=0)
+
+ free(d_original);
+
+ if (d_src!=0)
+
+ free(d_src);
+
+ if (ixs!=0)
+
+ free(ixs);
+
+ return -5;
+
+}
+
+
+
+void CFECRtpSession::UpdateFrames()
+
+{
+
+
+
+
+
+
+
+
+
+ int framecount;
+
+ FRAMEINFO * p;
+
+ FRAMEINFOLIST::iterator itera;
+
+
+
+ framecount = m_PreSendFrameList.size();
+
+ if(framecount==0)
+
+ return;
+
+
+
+
+
+ for(itera=m_PreSendFrameList.begin(); itera != m_PreSendFrameList.end(); ++itera){
+
+ p = *itera;
+
+ m_usLatestVideoSeq = p->us_latestseq;
+
+ m_oldVideotimestamp = p->ul_timestamp;
+
+ ProcessFrame(p->pData, p->l_datalen);
+
+ RemoveFrame(p);
+
+ p = 0;
+
+ }
+ m_PreSendFrameList.clear();
+
+ return ;
+
+
+
+
+
+ for(itera=m_PreSendFrameList.begin(); itera != m_PreSendFrameList.end(); ++itera){
+
+ p = *itera;
+
+ if(p->us_latestseq == uint16_t(m_usLatestVideoSeq+1)){
+
+ m_usLatestVideoSeq = p->us_latestseq;
+
+ m_oldVideotimestamp = p->ul_timestamp;
+
+ ProcessFrame(p->pData, p->l_datalen);
+
+ RemoveFrame(p);
+
+ p = 0;
+
+ m_PreSendFrameList.erase(itera);
+
+ UpdateFrames();
+
+ return;
+
+ }
+
+ }
+
+
+
+ if(framecount<3)
+
+ return;
+
+
+
+
+
+ FRAMEINFO *fff;
+
+ FRAMEINFOLIST::iterator kkk;
+
+ kkk=m_PreSendFrameList.begin();
+
+ fff = *kkk;
+
+ for(itera=kkk; itera != m_PreSendFrameList.end(); ++itera){
+
+ p = *itera;
+
+ if(fff->ul_timestamp > p->ul_timestamp){
+
+ kkk = itera;
+
+ fff = p;
+
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+ m_usLatestVideoSeq = fff->us_latestseq;
+
+ m_oldVideotimestamp = fff->ul_timestamp;
+
+ ProcessFrame(fff->pData, fff->l_datalen);
+
+
+ RemoveFrame(fff);
+
+ fff = 0;
+
+ m_PreSendFrameList.erase(kkk);
+
+
+
+ return;
+
+
+
+
+
+
+
+
+}
+
+
+
+void CFECRtpSession::ProcessFrame(unsigned char *recvdata, int recvlen)
+
+{
+
+ return;
+
+
+}
+
+
+
+void CFECRtpSession::RemoveFrame(FRAMEINFO *p)
+
+{
+
+ if(p->FECCoded)
+
+ delete p->pData;
+
+ else if(!p->FECCoded)
+
+ delete (p->pData-sizeof(FECHEADER));
+
+ delete p;
+
+}
Added: incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.h?rev=774247&view=auto
==============================================================================
--- incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.h (added)
+++ incubator/bluesky/trunk/sourcecode/teacher_src_1.0/fecrtpsession.h Wed May 13 07:44:26 2009
@@ -0,0 +1,252 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements. See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership. The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied. See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+
+
+// fecrtpsession.h: interface for the CFECRtpSession class.
+
+
+//////////////////////////////////////////////////////////////////////
+
+
+
+
+
+#include <rtpsession.h>
+
+#include <rtppacket.h>
+
+#include <rtpipv4address.h>
+
+#include <rtpsessionparams.h>
+
+#include <rtpudpv4transmitter.h>
+
+
+
+#if !defined(_FECRTPSESSION_H__INCLUDED_)
+
+#define _FECRTPSESSION_H__INCLUDED_
+
+
+
+
+
+
+
+#define uchar char
+
+#define ushort unsigned short
+
+#define ulong unsigned long
+
+
+
+#define ISPAD 1
+
+#define UNPAD 0
+
+#define FECCODED 1
+
+#define SENDFREQUENCY 1
+
+#define MAXSENDBUFFER 10000
+
+#define MAXFECPACKET 255
+
+
+
+#define FRAMENUM 2
+
+
+
+
+
+typedef struct _PADHEADER
+
+{
+
+ ushort paddled;
+
+ ushort padlen;
+
+}PADHEADER;
+
+
+
+typedef struct _FECHEADER
+
+{
+
+ ulong FecCoded :1;
+
+ ulong OriginalK :10;
+
+ ulong RedunN :11;
+
+ ulong OrigiCol :10;
+
+ ulong PacketSize;
+
+}FECHEADER;
+
+
+typedef struct _FECLISTINFO
+
+{
+
+ ulong ul_timestamp;
+
+ ulong ul_TotalNeedNum;
+
+ ulong ul_HaveArriveNum;
+
+ bool b_isEmpty;
+
+}FECLISTINFO;
+
+
+
+
+
+typedef struct _FRAMEINFO
+
+{
+
+ bool FECCoded;
+
+ ulong ul_timestamp;
+
+ uint16_t us_latestseq;
+
+ long l_datalen;
+
+ unsigned char *pData;
+
+}FRAMEINFO;
+
+
+
+typedef std::list<char*> FECDATALIST;
+
+typedef std::list<FRAMEINFO*> FRAMEINFOLIST;
+
+
+
+typedef unsigned char * PUCHAR;
+
+
+
+#define FECLISTSIZE 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+class CFECRtpSession : public RTPSession
+
+{
+
+public:
+
+ int ScreenWidth;
+
+ int ScreenHeight;
+
+private:
+
+ enum FECRTP{RtpMaxLen = 4096};
+
+
+private:
+
+ long GetDataLen(PUCHAR* d_src,long lPacketSize,unsigned int kCount);
+
+ void GetData(unsigned char* pData,PUCHAR* d_src,long lPacketSize,unsigned int kCount);
+
+ virtual void OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress);
+
+ int FECDecode(FECLISTINFO* pFecListInfo,FECDATALIST *pFecDataList, RTPPacket *pack);
+
+public:
+
+
+
+ inline uint16_t GetFrameNo(){return m_nFrameNo;};
+
+ int SendFECPacket(void *lpData, int datalen, int delay=5000);
+
+public:
+
+ CFECRtpSession();
+
+ virtual ~CFECRtpSession();
+
+private:
+
+ int FECEncodeSend(void* pData,long datalen, unsigned int FrameNo, int delay);
+
+ int GetRtpMaxLen();
+
+
+
+private:
+
+ void RemoveFrame(FRAMEINFO* p);
+
+ virtual void ProcessFrame(unsigned char* framedata, int framelen);
+
+ void UpdateFrames();
+
+
+ uint16_t m_nFrameNo;
+
+ int m_nRedundentRate;
+
+
+
+protected:
+
+ uint16_t m_usLatestVideoSeq;
+
+ int m_oldVideotimestamp;
+
+
+
+private:
+
+ FRAMEINFOLIST m_PreSendFrameList;
+
+ FECLISTINFO m_FECListInfo[FECLISTSIZE];
+
+ FECDATALIST m_VideoDataList[FECLISTSIZE];
+
+
+
+};
+
+
+
+#endif // !defined(_FECRTPSESSION_H__INCLUDED_)