Skip to content

Commit

Permalink
support multiple encoders.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Sep 9, 2019
1 parent 1d30860 commit c5117e5
Show file tree
Hide file tree
Showing 20 changed files with 552 additions and 304 deletions.
171 changes: 140 additions & 31 deletions Assets/uNvEncoder/Examples/Scenes/Example.unity
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,127 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &512188855
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 512188856}
- component: {fileID: 512188859}
- component: {fileID: 512188858}
- component: {fileID: 512188857}
m_Layer: 0
m_Name: Render Camera 2
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &512188856
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 512188855}
m_LocalRotation: {x: 0.31189665, y: 0.20372555, z: 0.068658166, w: 0.92547417}
m_LocalPosition: {x: -1.03, y: 1.4, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 963194228}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 33.321003, y: 30.167002, z: 17.708}
--- !u!114 &512188857
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 512188855}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0833f6be5a296eb4fb05eca6ff7e6439, type: 3}
m_Name:
m_EditorClassIdentifier:
filePath: test-2.h264
--- !u!114 &512188858
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 512188855}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 28d5e7ad59d1ad44f9e9ea9443db919c, type: 3}
m_Name:
m_EditorClassIdentifier:
encoder:
onEncoded:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 512188857}
m_MethodName: OnEncoded
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: uNvEncoder.Encoder+EncodedCallback, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
texture: {fileID: 8400000, guid: fdebf29a4668aa5438593de1aad273f3, type: 2}
frameRate: 60
forceIdrFrame: 0
--- !u!20 &512188859
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 512188855}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 8400000, guid: fdebf29a4668aa5438593de1aad273f3, type: 2}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!1 &705507993
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -292,6 +413,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1076557919}
- {fileID: 512188856}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand All @@ -305,11 +427,10 @@ GameObject:
m_Component:
- component: {fileID: 1076557919}
- component: {fileID: 1076557923}
- component: {fileID: 1076557922}
- component: {fileID: 1076557921}
- component: {fileID: 1076557920}
m_Layer: 0
m_Name: Render Camera
m_Name: Render Camera 1
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -354,38 +475,26 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 28d5e7ad59d1ad44f9e9ea9443db919c, type: 3}
m_Name:
m_EditorClassIdentifier:
encoder: {fileID: 1076557922}
encoder:
onEncoded:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1076557920}
m_MethodName: OnEncoded
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: uNvEncoder.Encoder+EncodedCallback, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
texture: {fileID: 8400000, guid: 314a1f1bf10d90f4eb4025543112bd83, type: 2}
frameRate: 60
forceIdrFrame: 0
--- !u!114 &1076557922
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1076557918}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6ae92fb89500a024088102c416bc5426, type: 3}
m_Name:
m_EditorClassIdentifier:
onEncoded:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1076557920}
m_MethodName: OnEncoded
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: uNvEncoder.uNvEncoderEncode+EncodedCallback, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!20 &1076557923
Camera:
m_ObjectHideFlags: 0
Expand Down
15 changes: 5 additions & 10 deletions Assets/uNvEncoder/Examples/Scripts/TextureEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ namespace uNvEncoder.Examples

public class TextureEncoder : MonoBehaviour
{
public uNvEncoder encoder = null;
public Encoder encoder = new Encoder();
public Texture texture = null;
public int frameRate = 60;
public bool forceIdrFrame = true;

void OnEnable()
{
Assert.IsNotNull(encoder);
Assert.IsNotNull(texture);
encoder.StartEncode(texture.width, texture.height, frameRate);
encoder.Create(texture.width, texture.height, frameRate);
StartCoroutine(EncodeLoop());
}

void OnDisable()
{
StopAllCoroutines();
encoder.StopEncode();
encoder.Destroy();
}

IEnumerator EncodeLoop()
Expand All @@ -37,14 +36,10 @@ IEnumerator EncodeLoop()

void Encode()
{
if (!encoder || !encoder.isValid) return;

if (!texture) return;

if (!encoder.Encode(texture, forceIdrFrame))
{
Debug.LogError("Encode() failed.");
}
encoder.Update();
encoder.Encode(texture, forceIdrFrame);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RenderTexture:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Render Camera
m_Name: Render Camera 1
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
Expand Down
36 changes: 36 additions & 0 deletions Assets/uNvEncoder/Examples/Textures/Render Camera 2.renderTexture
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!84 &8400000
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Render Camera 2
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 1024
m_Height: 1024
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1

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

Binary file modified Assets/uNvEncoder/Plugins/x86/uNvEncoder.dll
Binary file not shown.
Binary file modified Assets/uNvEncoder/Plugins/x86_64/uNvEncoder.dll
Binary file not shown.
Loading

0 comments on commit c5117e5

Please sign in to comment.