Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Create or overwrite tag

on:
workflow_dispatch:
inputs:
tag_name:
description: Tag name to create or overwrite
required: true
type: string

permissions:
contents: write

jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create or overwrite tag
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
if [ -z "$TAG_NAME" ]; then
echo "tag_name is required"
exit 1
fi

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git fetch --tags --force

if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
git tag -d "$TAG_NAME"
fi

git push origin ":refs/tags/$TAG_NAME" || true

git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin "refs/tags/$TAG_NAME"

echo "Tag '$TAG_NAME' has been created/overwritten at commit $GITHUB_SHA"
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private VideoSurface MakePlaneSurface(string goName)
go.transform.localScale = new Vector3(1.0f, 1.333f, 0.5f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down Expand Up @@ -360,7 +360,7 @@ private static VideoSurface MakeImageSurface(string goName)
go.transform.localScale = new Vector3(4.5f, 3f, 1f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private static VideoSurface MakePlaneSurface(string goName)
go.transform.localScale = new Vector3(0.25f, 0.5f, 0.5f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ private static VideoSurface MakeImageSurface(string goName)
go.transform.localScale = new Vector3(2f, 3f, 1f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static VideoSurface MakePlaneSurface(string goName)
go.transform.localScale = new Vector3(0.25f, 0.5f, 0.5f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ private static VideoSurface MakeImageSurface(string goName)
go.transform.localScale = new Vector3(2f, 3f, 1f);

// configure videoSurface
var videoSurface = go.AddComponent<VideoSurface>();
var videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ private IEnumerator PreparationFilePath(Action<string> callback)
yield return www.SendWebRequest();


#if UNITY_2020_1_OR_NEWER
if (www.result != UnityWebRequest.Result.Success)
#else
if (www.isNetworkError || www.isHttpError)
#endif
{
Debug.LogError("Failed to load file: " + www.error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private static VideoSurface MakePlaneSurface(string goName)
go.transform.localScale = new Vector3(0.25f, 0.5f, .5f);

// configure videoSurface
VideoSurface videoSurface = go.AddComponent<VideoSurface>();
VideoSurface videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down Expand Up @@ -331,7 +331,7 @@ private static VideoSurface makeImageSurface(string goName)
go.transform.localScale = new Vector3(3f, 4f, 1f);

// configure videoSurface
VideoSurface videoSurface = go.AddComponent<VideoSurface>();
VideoSurface videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private static VideoSurface makeImageSurface(string goName)
go.transform.localScale = new Vector3(3f, 4f, 1f);

// configure videoSurface
VideoSurface videoSurface = go.AddComponent<VideoSurface>();
VideoSurface videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static VideoSurface makeImageSurface(string goName)
go.transform.localScale = new Vector3(3f, 4f, 1f);

// configure videoSurface
VideoSurface videoSurface = go.AddComponent<VideoSurface>();
VideoSurface videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private static VideoSurface makeImageSurface(string goName)
go.transform.localScale = new Vector3(3f, 4f, 1f);

// configure videoSurface
VideoSurface videoSurface = go.AddComponent<VideoSurface>();
VideoSurface videoSurface = go.AddComponent<VideoSurfaceYUV>();
return videoSurface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,34 @@ public class CustomRenderAudio : MonoBehaviour


private const int CHANNEL = 2;
private const int SAMPLE_RATE = 44100;
private const int SAMPLE_RATE = 48000;
private const int PULL_FREQ_PER_SEC = 100;


private RingBuffer<float> _audioBuffer;
private AudioSource _audioSource;
private AudioClip _audioClip;
Pcm16AudioWriter _audioWriter;


private Thread _pullAudioFrameThread;
private System.Object _rtcLock = new System.Object();

private int _writeCount;
private int _readCount;



private void Start()
{
LoadAssetData();
if (CheckAppId())
{
_audioWriter = new Pcm16AudioWriter("CustomRenderAudio_" + DateTime.Now.ToString("yyyyMMddHHmmss"), SAMPLE_RATE, CHANNEL);
InitRtcEngine();
JoinChannel();
var aud = InitAudioSource();
StartPullAudioFrame(aud, "externalClip");
_audioSource = InitAudioSource();
StartPullAudioFrame(_audioSource, "externalClip");
}
}

Expand Down Expand Up @@ -99,6 +104,9 @@ private void InitRtcEngine()
context.areaCode = AREA_CODE.AREA_CODE_GLOB;
RtcEngine.Initialize(context);
RtcEngine.InitEventHandler(handler);

// RtcEngine.SetParameters("{\"che.audio.use.call.mode\":false}");
RtcEngine.SetParameters("{\"che.audio.keep.audiosession\":true}");
}
}

Expand All @@ -107,6 +115,8 @@ private void JoinChannel()
lock (_rtcLock)
{
RtcEngine.EnableAudio();
RtcEngine.EnableVideo();
RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
//no enableAudioDevice to set false? how this methond work?
var nRet = RtcEngine.SetExternalAudioSink(true, SAMPLE_RATE, CHANNEL);
this.Log.UpdateLog("SetExternalAudioSink ret:" + nRet);
Expand Down Expand Up @@ -135,7 +145,8 @@ private void StartPullAudioFrame(AudioSource aud, string clipName)
_pullAudioFrameThread.Start();

_audioClip = AudioClip.Create(clipName,
SAMPLE_RATE / PULL_FREQ_PER_SEC, CHANNEL, SAMPLE_RATE, true,
SAMPLE_RATE / PULL_FREQ_PER_SEC * CHANNEL,
CHANNEL, SAMPLE_RATE, true,
OnAudioRead);
aud.clip = _audioClip;
aud.loop = true;
Expand All @@ -155,9 +166,20 @@ private void OnDestroy()
RtcEngine.LeaveChannel();
RtcEngine.Dispose();
RtcEngine = null;
_audioWriter.Flush();
}
//need wait pullAudioFrameThread stop
_pullAudioFrameThread.Join();

if (_audioSource != null)
{
_audioSource.Stop();
}

if (_audioClip != null)
{
Destroy(_audioClip);
}
}

private void PullAudioFrameThread()
Expand Down Expand Up @@ -197,18 +219,19 @@ private void PullAudioFrameThread()
}
nRet = -1;
nRet = RtcEngine.PullAudioFrame(audioFrame);
Debug.Log("PullAudioFrame returns: " + nRet);
// Debug.Log("PullAudioFrame returns: " + nRet);

if (nRet == 0)
{
Marshal.Copy((IntPtr)audioFrame.buffer, byteBuffer, 0, byteBuffer.Length);
var floatArray = ConvertByteToFloat16(byteBuffer);
_audioWriter.PutData(byteBuffer);
lock (_audioBuffer)
{
_audioBuffer.Put(floatArray);
}
_writeCount += floatArray.Length;

}
}

Expand Down Expand Up @@ -246,19 +269,14 @@ private void OnAudioRead(float[] data)
//if (!_startSignal) return;
lock (_audioBuffer)
{
for (var i = 0; i < data.Length; i++)
if(_audioBuffer.Count >= data.Length)
{

if (_audioBuffer.Count > 0)
{
data[i] = _audioBuffer.Get();
}
else
{
data[i] = 0;
}
_audioBuffer.MoveTo(data);
}
else
{
Array.Clear(data,0, data.Length);
}

//readCount += 1;
}

Expand Down
Loading