-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathDataSource.java
144 lines (124 loc) · 3.87 KB
/
DataSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.otaliastudios.transcoder.source;
import android.media.MediaFormat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.otaliastudios.transcoder.engine.TrackType;
import com.otaliastudios.transcoder.postprocessor.PostProcessor;
import java.nio.ByteBuffer;
/**
* Represents the source of input data.
*/
public interface DataSource {
/**
* Returns an handler that need to be executed with the raw data source data
* before that it gets encoded.
*
* @return the PostProcessor object
*/
PostProcessor getPostProcessor();
/**
* Sets the handler that needs to be called before that the raw data source data
* gets sent to the encoder.
*
* @param postProcessor the PostProcessor object
*/
void setPostProcessor(@NonNull PostProcessor postProcessor);
/**
* Metadata information. Returns the video orientation, or 0.
*
* @return video metadata orientation
*/
int getOrientation();
/**
* Metadata information. Returns the video location, or null.
*
* @return video location or null
*/
@Nullable
double[] getLocation();
/**
* Returns the video total duration in microseconds.
*
* @return duration in us
*/
long getDurationUs();
/**
* Called before starting to inspect the input format for this track.
* Can return null if this media does not include this track type.
*
* @param type track type
* @return format or null
*/
@Nullable
MediaFormat getTrackFormat(@NonNull TrackType type);
/**
* Called before starting, but after {@link #getTrackFormat(TrackType)},
* to select the given track.
*
* @param type track type
*/
void selectTrack(@NonNull TrackType type);
/**
* Moves all selected tracks to the specified presentation time.
* The timestamp should be between 0 and {@link #getDurationUs()}.
* The actual timestamp might differ from the desired one because of
* seeking constraints (e.g. seek to sync frames).
*
* @param desiredTimestampUs requested timestamp
* @return actual timestamp
*/
long seekTo(long desiredTimestampUs);
/**
* Returns true if we can read the given track at this point.
* If true if returned, source should expect a {@link #readTrack(Chunk)} call.
*
* @param type track type
* @return true if we can read this track now
*/
boolean canReadTrack(@NonNull TrackType type);
/**
* Called to read contents for the current track type.
* Contents should be put inside {@link DataSource.Chunk#buffer}, and the
* other chunk flags should be filled.
*
* @param chunk output chunk
*/
void readTrack(@NonNull DataSource.Chunk chunk);
/**
* Returns the total number of microseconds that have been read until now.
*
* @return total read us
*/
long getReadUs();
/**
* When this source has been totally read, it can return true here to
* notify an end of input stream.
*
* @return true if drained
*/
boolean isDrained();
/**
* Called to release resources for a given track.
* @param type track type
*/
void releaseTrack(@NonNull TrackType type);
/**
* Rewinds this source, moving it to its default state.
* To be used again, tracks will be selected again.
* After this call, for instance,
* - {@link #getReadUs()} should be 0
* - {@link #isDrained()} should be false
* - {@link #readTrack(Chunk)} should return the very first bytes
*/
void rewind();
/**
* Represents a chunk of data.
* Can be used to read input from {@link #readTrack(Chunk)}.
*/
class Chunk {
public ByteBuffer buffer;
public boolean isKeyFrame;
public long timestampUs;
public int bytes;
}
}