1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tv.tuner.testing.buffer;
17 
18 import android.os.SystemClock;
19 import com.android.tv.tuner.exoplayer.buffer.SampleChunk;
20 import com.android.tv.tuner.exoplayer.buffer.SamplePool;
21 import com.google.android.exoplayer.SampleHolder;
22 import java.io.File;
23 import java.io.IOException;
24 
25 /** A Sample chunk that is slow for testing */
26 public class VerySlowSampleChunk extends SampleChunk {
27 
28     /** Creates a {@link VerySlowSampleChunk}. */
29     public static class VerySlowSampleChunkCreator extends SampleChunkCreator {
30         @Override
createSampleChunk( SamplePool samplePool, File file, long startPositionUs, ChunkCallback chunkCallback)31         public SampleChunk createSampleChunk(
32                 SamplePool samplePool,
33                 File file,
34                 long startPositionUs,
35                 ChunkCallback chunkCallback) {
36             return new VerySlowSampleChunk(
37                     samplePool, file, startPositionUs, System.currentTimeMillis(), chunkCallback);
38         }
39     }
40 
VerySlowSampleChunk( SamplePool samplePool, File file, long startPositionUs, long createdTimeMs, ChunkCallback chunkCallback)41     private VerySlowSampleChunk(
42             SamplePool samplePool,
43             File file,
44             long startPositionUs,
45             long createdTimeMs,
46             ChunkCallback chunkCallback) {
47         super(samplePool, file, startPositionUs, createdTimeMs, chunkCallback);
48     }
49 
50     @Override
write(SampleHolder sample, IoState state)51     protected void write(SampleHolder sample, IoState state) throws IOException {
52         SystemClock.sleep(10);
53         super.write(sample, state);
54     }
55 }
56