Flash Player 10 and Adobe AIR 1.5 introduce a new communications protocol called the Real-Time Media Flow Protocol (RTMFP). The most important features of RTMFP include low latency, end-to-end peering capability, security and scalability. These properties make RTMFP especially well suited for developing real-time collaboration applications by not only providing superior user experience but also reducing cost for operators.
In order to use RTMFP, Flash Player endpoints must connect to an RTMFP-capable server, such as the Adobe Stratus service. Stratus is a Beta hosted rendezvous service that aids establishing communications between Flash Player endpoints. Unlike Flash Media Server, Stratus does not support media relay, shared objects, scripting, etc. So by using Stratus, you can only develop applications where Flash Player endpoints are directly communicating with each other.
How will I make a P2P connection through Flash Player 10 or Adobe AIR 1.5? Connections from a SWF through an RTMFP-capable server will be assigned a temporary unique ID that is infeasible to guess or forge. Other SWFs connected to the same server can subscribe to the streams and events from that ID once the broadcasting SWF agrees to the connection.
Can I get started with RTMFP now? Stratus will allow you to begin developing RTMFP-enabled applications. It will be available on Adobe Labs before the end of the year.
C#でC++dllの関数使うよって宣言
[csharp][DllImport(“pcp.dll”)]
private static extern int call_array([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)]string[] files, int length);
[/csharp]
C#側コード
[csharp]string[] files = new string[2];
files[0] = “日本語1″;
files[1] = “日本語2″;
int ret = call_array(files,2);
return ret;[/csharp]
C++側
[cpp]int call_array( wchar_t* files, int length ) {
setlocale(LC_ALL,”japanese”);
for ( int i=0; i<length; i++ ) {
wprintf(L”%d: %s\n”,i,(files+i));
}
return 10;
}[/cpp]
defファイルに書いとく。
C++からC#のコールバックに文字列の配列を渡す
C#のコールバック
[csharp]public static int onReceivedFiles(IntPtr ptr, int nVal) {
IntPtr pptr;
string[] files = new string[nVal];
for( int n = 0; n < nVal; n++ ) {
// スタックに積まれて来るのはポインタのみなので
pptr = Marshal.ReadIntPtr( ptr, n * 4 );
files[n] = Marshal.PtrToStringAuto( pptr );
}
return 1;
}[/csharp]
コールバック関数を渡す先のC++側関数とdelegate
[cpp][DllImport(“pcp.dll”)]
private static extern int start(StringArrayCallback cb);
public delegate int StringArrayCallback(IntPtr ptr, int nVal);
[/cpp]
C++にコールバック関数を渡す
[cpp]StringArrayCallback cb = new StringArrayCallback(onReceivedFiles);
int ret = start(cb);[/cpp]
typedef struct {
int frameIndex; /* Index into sample array. */
int maxFrameIndex;
std::queue qu_microphone;
std::queue qu_speex;
std::queue qu_speaker;
} paTestData;
// speex globals
SpeexBits encoder_bits;
SpeexBits decoder_bits;
void encoder_state;
void decoder_state;
unsigned int speex_frame_size; // 320 or 640 or ..
unsigned int speex_packet_size = 74; // 74 or something
/ This routine will be called by the PortAudio engine when audio is needed. It may be called at interrupt level on some machines so don’t do anything that could mess up the system like calling malloc() or free(). /
static int echo( const void inputBuffer,
void outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo timeInfo,
PaStreamCallbackFlags statusFlags,
void userData
)
{
paTestData *data = (paTestData*)userData;
const SAMPLE *rptr = (const SAMPLE*)inputBuffer;
SAMPLE *wptr = (SAMPLE*)outputBuffer;
std::queue & qu_microphone = data->qu_microphone;
//std::queue& qu_speex = data->qu_speex;
std::queue & qu_speaker = data->qu_microphone; // point at the same queue, to feed the speaker what we got from the microphone
endif
long framesToCalc;
long i;
int finished;
unsigned long framesLeft = data->maxFrameIndex – data->frameIndex;
/**********************/
int main(void)
{
PaStreamParameters inputParameters,
outputParameters;
PaStream stream;
PaError err = paNoError;
int totalFrames;
std::cout < < “patest_record.c”;
paTestData data;
data.maxFrameIndex = totalFrames = NUM_SECONDS * SAMPLE_RATE; /* Record for a few seconds. */
data.frameIndex = 0;
int numSamples = totalFrames * NUM_CHANNELS;
int numBytes = numSamples * sizeof(SAMPLE);
int tmp;
for (i = codecs.begin(); i < codecs.end(); i++) {
if (!engine->FindCodec(*i))
continue;
if (first) {
LOG(LS_INFO) < < “Using ” << i->name < < “/” << i->clockrate;
pt = i->id;
first = false;
}
}
if (first) {
// We’re being asked to set an empty list of codecs. This will only happen when
// working with a buggy client; let’s try PCMU.
LOG(LS_WARNING) < < “Received empty list of codces; using PCMU/8000”;
}
}
// マイクから新しいデータがとれたら、リモートに送る
void PortAudioMediaChannel::OnReadFromMic( PortAudioMediaChannel channel )
{
//char buf[max_size];
int size = PORTAUDIO_PACKET_LENGTH;
float buff[PORTAUDIO_PACKET_LENGTH/4];
int len;
talk_base::CritScope cs(&crit_microphone);
portaudiomediaengine.h
[cpp]
/
* Jingle call example
* Copyright 2004–2005, Google Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /
// PortAudioMediaEngine is a Linphone implementation of MediaEngine
ifndef TALK_SESSION_PHONE_PORTAUDIOMEDIAENGINE_H_
define TALK_SESSION_PHONE_PORTAUDIOMEDIAENGINE_H_
include “talk/third_party/mediastreamer/mediastream.h”
include “talk/base/asyncsocket.h”
include “talk/base/scoped_ptr.h”
include “talk/session/phone/mediaengine.h”
include “talk/base/criticalsection.h”
include “portaudio.h”
include
include
// Engine settings
define ENGINE_BUFFER_SIZE 2048
// PortAudio settings
define PA_SAMPLE_TYPE (paFloat32) // 32 bit floating point output