/
DataSpec.java
120 lines (110 loc) · 3.99 KB
/
DataSpec.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
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer.upstream;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.util.Assertions;
import android.net.Uri;
/**
* Defines a region of media data.
*/
public final class DataSpec {
/**
* Identifies the source from which data should be read.
*/
public final Uri uri;
/**
* True if the data at {@link #uri} is the full stream. False otherwise. An example where this
* may be false is if {@link #uri} defines the location of a cached part of the stream.
*/
public final boolean uriIsFullStream;
/**
* The absolute position of the data in the full stream.
*/
public final long absoluteStreamPosition;
/**
* The position of the data when read from {@link #uri}. Always equal to
* {@link #absoluteStreamPosition} if {@link #uriIsFullStream}.
*/
public final long position;
/**
* The length of the data. Greater than zero, or equal to {@link C#LENGTH_UNBOUNDED}.
*/
public final long length;
/**
* A key that uniquely identifies the original stream. Used for cache indexing. May be null if the
* {@link DataSpec} is not intended to be used in conjunction with a cache.
*/
public final String key;
/**
* Construct a {@link DataSpec} for the given uri and with {@link #key} set to null.
*
* @param uri {@link #uri}.
*/
public DataSpec(Uri uri) {
this(uri, 0, C.LENGTH_UNBOUNDED, null);
}
/**
* Construct a {@link DataSpec} for which {@link #uriIsFullStream} is true.
*
* @param uri {@link #uri}.
* @param absoluteStreamPosition {@link #absoluteStreamPosition}, equal to {@link #position}.
* @param length {@link #length}.
* @param key {@link #key}.
*/
public DataSpec(Uri uri, long absoluteStreamPosition, long length, String key) {
this(uri, absoluteStreamPosition, length, key, absoluteStreamPosition, true);
}
/**
* Construct a {@link DataSpec} for which {@link #uriIsFullStream} is false.
*
* @param uri {@link #uri}.
* @param absoluteStreamPosition {@link #absoluteStreamPosition}.
* @param length {@link #length}.
* @param key {@link #key}.
* @param position {@link #position}.
*/
public DataSpec(Uri uri, long absoluteStreamPosition, long length, String key, long position) {
this(uri, absoluteStreamPosition, length, key, position, false);
}
/**
* Construct a {@link DataSpec}.
*
* @param uri {@link #uri}.
* @param absoluteStreamPosition {@link #absoluteStreamPosition}.
* @param length {@link #length}.
* @param key {@link #key}.
* @param position {@link #position}.
* @param uriIsFullStream {@link #uriIsFullStream}.
*/
public DataSpec(Uri uri, long absoluteStreamPosition, long length, String key, long position,
boolean uriIsFullStream) {
Assertions.checkArgument(absoluteStreamPosition >= 0);
Assertions.checkArgument(position >= 0);
Assertions.checkArgument(length > 0 || length == C.LENGTH_UNBOUNDED);
Assertions.checkArgument(absoluteStreamPosition == position || !uriIsFullStream);
this.uri = uri;
this.uriIsFullStream = uriIsFullStream;
this.absoluteStreamPosition = absoluteStreamPosition;
this.position = position;
this.length = length;
this.key = key;
}
@Override
public String toString() {
return "DataSpec[" + uri + ", " + uriIsFullStream + ", " + absoluteStreamPosition + ", " +
position + ", " + length + ", " + key + "]";
}
}