-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for large video file uploads (tus.io) #46
Merged
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
963e7b9
Adding Tus .NET implementation and changing the .NET version to 4 to …
juniorxsound 2af780b
Adding a method to request an upload using the `TusClient()`
juniorxsound 592e69f
Merge branch 'master' into tus-upload
juniorxsound 4e54e8f
Setting up initial arch sturctue for the Vimeo Tus uploader
juniorxsound 0705197
Improving VideoChunk class and finishing byte reading
juniorxsound 4064cb7
Calling the VimeoUploader from the VimeoApi class - and it works 🤩
juniorxsound 9cff299
Making the VimeoUploader upload videos using the Vimeo tus API
juniorxsound f386cda
Testing long recording and implementing more events
juniorxsound 6c4ad8c
Adding events, proper styling and splitting VideoChunk from VimeoUplo…
juniorxsound d6b52c6
Hiding all components additional components in recorder scene from th…
juniorxsound 0246e39
Hiding video controller from the inspector as well
juniorxsound c242d0e
Fixing typo in file name
juniorxsound 77a0b23
Implementing VimeoUploader into the VimeoPublisher class
juniorxsound bb82d0c
Style formatting for all changed files
juniorxsound 741a516
Implementing the missing events for the VimeoUploader
juniorxsound fbdf947
Changing the architecture so VimeoUploader extends the VimeoApi inste…
juniorxsound 4e0c477
Setting the video information right after a tus video resource has be…
juniorxsound 2427d90
Cleaning up the VimeoUploader refactor
juniorxsound 1be6de6
Fixing the message sent on upload complete, and making sure the tests…
juniorxsound 6e9a088
Deleting all legacy upload code from VimeoApi 🛠
juniorxsound cd23dcb
Moving the OnUploadProgress and OnUploadComplete events from the Api …
juniorxsound d684763
Minor styling fixes in VimeoPublisher and VimeoUploader
juniorxsound 65b761e
Changing the RequestComplete event to OnUploadInit
juniorxsound b3d586b
Adding getters and unit testing for all variables in VideoChunk.cs
juniorxsound 36b9857
Setting up the VimeoUploader unit testing and getters for all private…
juniorxsound f8b63e3
Destorying the gameobjects properly in unit tests
juniorxsound 6ab74a9
Add new default to test config
caseypugh ebbf9dd
Resolve issues with regex matching (and add tests)
caseypugh 94ac29a
Added more tests to VimeoUploader and VideoChunk
caseypugh c540ad4
Include particle system so that the Recorder scene works
caseypugh 37af769
Changing naming convention to m_camelCase for private and camelCase f…
juniorxsound ca18fda
Getting rid of unneeded argument in CreateChunks in VimeoUploader and…
juniorxsound 7e57f3e
Removing the tus response event after the video resource was created …
juniorxsound 6ab4a89
Fixing unreachable code block and and unit test for it
juniorxsound 5e61dd1
Testing uploading & adding to folder
caseypugh 49a7ce4
DRYing up some reusable logic
caseypugh b51816c
Nicer handling of VimeoPublisher when video doesn't exist on hard drive
juniorxsound 072d30b
Fix test on Windows
caseypugh 4b019e9
Moving the response handling to VimeoVideo and deleting the functions…
juniorxsound a1e7eee
Writing a generic VimeoVideo that supports the legacy style and tus s…
juniorxsound 59ac6e3
decrease timeout to 30s
caseypugh c2f8125
DRY up all the response handling
caseypugh 8cac312
remove duplicate error log
caseypugh c0528fa
Removed OnPatchComplete and updated VimeoPublisher
caseypugh 2ed7f59
also remove event from VimeoApi
caseypugh a67bc69
Multiple upload testing (and add support for paging in api)
caseypugh 2846a06
Adding chunk based upload progress so the progress bar is responsive …
juniorxsound f62acef
Add optional argument to the VimeoPublisher for easier testing of dif…
juniorxsound 7971c3f
Changing the `VimeoUploader` Queue to a List so it stores all the chu…
juniorxsound 93bb99a
Implementing the onProgress in the VimeoUploader and DRY'ing VideoChunk
juniorxsound 7b4ec62
Changing naming convention in VimeoRecorder
juniorxsound c96d027
Adding a bunch of tests to `VimeoUploader` and `VideoChunk` and handl…
juniorxsound 3af05f4
Adding `VideoChunk` tests
juniorxsound 253b068
Adding VimeoUploader test for uploading a very big file without recor…
juniorxsound 1f946de
Changing the gitignore so it ignores all videos in the test folder
juniorxsound a71fc12
Fix name to specify the type of test
caseypugh 7b4f825
adjust naming to specify platform and unity version
caseypugh 7d4c412
Adding temporary naming / privacy workaround so the VimeoUploader cou…
juniorxsound 17a0e9c
AVPro Movie Capture test
caseypugh 464e14a
Merge branch 'tus-upload' of https://github.com/vimeo/vimeo-unity-sdk…
caseypugh 7a0b413
Move version error check into _before
caseypugh 2a30f4e
check that fileinfo is not null
caseypugh 86ef91e
Fixes unhandled onProgress error when calling GetBytesUploaded
juniorxsound a932b46
Moving all the tests into an Editor folder so they don't get included…
juniorxsound ee67c7b
Move tests back into root folder
caseypugh 237a52f
Ignore all mp4 when commiting
juniorxsound 5e74e22
Add support for resumable chunks (for spotty internet connections)
caseypugh 97d5f3d
Updating it so it should ignore the meta file created for the video a…
juniorxsound 1ebaa82
Updating gitignore to ignore all mp4's and meta files created by Unity
juniorxsound 9732b46
Move version init to _Before
caseypugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ public class VimeoUploader : VimeoApi | |
public event UploadAction OnUploadProgress; | ||
public event RequestAction OnUploadComplete; | ||
|
||
private Queue<VideoChunk> m_chunks; | ||
public Queue<VideoChunk> chunks { | ||
private List<VideoChunk> m_chunks; | ||
public List<VideoChunk> chunks { | ||
get { | ||
return m_chunks; | ||
} | ||
|
@@ -61,10 +61,13 @@ public float uploadProgress { | |
return m_uploadProgress; | ||
} | ||
} | ||
private int currentChunkIndex = 0; | ||
private VideoChunk lastChunk; | ||
|
||
public void Init(string _token, int _maxChunkByteSize = 1024 * 1024 * 128) | ||
{ | ||
m_chunks = new Queue<VideoChunk>(); | ||
currentChunkIndex = 0; | ||
m_chunks = new List<VideoChunk>(); | ||
token = _token; | ||
m_maxChunkSize = _maxChunkByteSize; | ||
} | ||
|
@@ -79,8 +82,19 @@ private void RequestComplete(string response) | |
m_vimeoUrl = rawJSON["link"].Value; | ||
CreateChunks(m_fileInfo, tusUploadLink); | ||
|
||
VideoChunk firstChunk = m_chunks.Dequeue(); | ||
firstChunk.Upload(); | ||
VideoChunk currentChunk = GetNextChunk(); | ||
currentChunk.Upload(); | ||
} | ||
juniorxsound marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private VideoChunk GetNextChunk() | ||
{ | ||
if (HasChunksLeftToUpload()) { | ||
VideoChunk currentChunk = m_chunks[currentChunkIndex]; | ||
RegisterChunkEvents(currentChunk); | ||
return currentChunk; | ||
} | ||
|
||
juniorxsound marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return null; | ||
} | ||
|
||
public void Upload(string _file) | ||
|
@@ -92,30 +106,44 @@ public void Upload(string _file) | |
StartCoroutine(RequestTusResource("me/videos", m_fileInfo.Length)); | ||
} | ||
|
||
private void OnCompleteChunk(VideoChunk chunk, string msg) | ||
private void OnCompleteChunk(VideoChunk chunk, string latestUploadedByte) | ||
{ | ||
//Emit the event | ||
if (OnChunckUploadComplete != null) { | ||
OnChunckUploadComplete(chunk, msg); | ||
// OnUploadProgress("Uploading", 1f); | ||
OnChunckUploadComplete(chunk, latestUploadedByte); | ||
} | ||
|
||
Destroy(chunk); | ||
|
||
UploadNextChunk(); | ||
currentChunkIndex++; | ||
UploadNextChunk(GetNextChunk()); | ||
} | ||
|
||
private void OnUploadChunkProgress(VideoChunk chunk, float progress) | ||
{ | ||
//Calculate the addition of each chunk to the total file length (in bytes) | ||
m_uploadProgress = (chunks.Count + 1) * ((progress * (float)chunk.chunkSize) / (float)m_fileInfo.Length); | ||
if (OnUploadProgress != null) { | ||
OnUploadProgress("Uploading", m_uploadProgress); | ||
} | ||
} | ||
|
||
private void RegisterChunkEvents(VideoChunk chunk) | ||
{ | ||
chunk.OnChunkUploadComplete += OnCompleteChunk; | ||
chunk.OnChunkUploadError += OnChunkError; | ||
chunk.OnChunkUploadProgress += OnUploadChunkProgress; | ||
} | ||
|
||
private void DisposeChunkEvents(VideoChunk chunk) | ||
{ | ||
chunk.OnChunkUploadComplete -= OnCompleteChunk; | ||
chunk.OnChunkUploadError -= OnChunkError; | ||
chunk.OnChunkUploadProgress -= OnUploadChunkProgress; | ||
} | ||
|
||
private void OnChunkError(VideoChunk chunk, string err) | ||
{ | ||
if (OnChunckUploadError != null) { | ||
if (OnChunckUploadError != null && chunk != null) { | ||
OnChunckUploadError(chunk, err); | ||
} | ||
} | ||
|
@@ -127,7 +155,7 @@ public void CreateChunks(FileInfo fileInfo, string tusUploadLink) | |
|
||
for (int i = 0; i < m_numChunks; i++) { | ||
int indexByte = m_maxChunkSize * i; | ||
VideoChunk chunk = this.gameObject.AddComponent<VideoChunk>(); | ||
VideoChunk chunk = gameObject.AddComponent<VideoChunk>(); | ||
chunk.hideFlags = HideFlags.HideInInspector; | ||
|
||
//If we are at the last chunk set the max chunk size to the fractional remainder | ||
|
@@ -137,21 +165,22 @@ public void CreateChunks(FileInfo fileInfo, string tusUploadLink) | |
} else { | ||
chunk.Init(indexByte, tusUploadLink, fileInfo.FullName, m_maxChunkSize); | ||
} | ||
|
||
chunk.OnChunkUploadComplete += OnCompleteChunk; | ||
chunk.OnChunkUploadError += OnChunkError; | ||
chunk.OnChunkUploadProgress += OnUploadChunkProgress; | ||
m_chunks.Enqueue(chunk); | ||
m_chunks.Add(chunk); | ||
} | ||
} | ||
|
||
public void UploadNextChunk() | ||
public void UploadNextChunk(VideoChunk currentChunk) | ||
{ | ||
//Make sure the queue is not empty | ||
if (m_chunks.Count != 0) { | ||
VideoChunk currentChunk = m_chunks.Dequeue(); | ||
|
||
if (lastChunk != null) { | ||
DisposeChunkEvents(lastChunk); | ||
} | ||
|
||
//Make sure there are still chunks to upload | ||
if (currentChunk != null) { | ||
currentChunk.Upload(); | ||
|
||
//Store the reference to latest uploaded chunk to de-register events | ||
lastChunk = currentChunk; | ||
} else { | ||
if (OnUploadProgress != null) { | ||
OnUploadProgress("UploadComplete", 1f); | ||
|
@@ -161,5 +190,13 @@ public void UploadNextChunk() | |
} | ||
} | ||
} | ||
|
||
private bool HasChunksLeftToUpload() | ||
{ | ||
if (currentChunkIndex < m_chunks.Count) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a more future proof way of checking would be to create a method called
|
||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just call this
byteChunkSize
?