summaryrefslogtreecommitdiff
path: root/apps/codecs/tta.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/tta.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/tta.c')
-rw-r--r--apps/codecs/tta.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/apps/codecs/tta.c b/apps/codecs/tta.c
index 1d0846ea61..c75f2b0a57 100644
--- a/apps/codecs/tta.c
+++ b/apps/codecs/tta.c
@@ -34,36 +34,36 @@ CODEC_HEADER
34static int32_t samples[PCM_BUFFER_LENGTH * 2] IBSS_ATTR; 34static int32_t samples[PCM_BUFFER_LENGTH * 2] IBSS_ATTR;
35 35
36/* this is the codec entry point */ 36/* this is the codec entry point */
37enum codec_status codec_main(void) 37enum codec_status codec_main(enum codec_entry_call_reason reason)
38{
39 if (reason == CODEC_LOAD) {
40 /* Generic codec initialisation */
41 ci->configure(DSP_SET_SAMPLE_DEPTH, TTA_OUTPUT_DEPTH - 1);
42 }
43
44 return CODEC_OK;
45}
46
47/* this is called for each file to process */
48enum codec_status codec_run(void)
38{ 49{
39 tta_info info; 50 tta_info info;
40 int status;
41 unsigned int decodedsamples; 51 unsigned int decodedsamples;
42 int endofstream; 52 int endofstream;
43 int new_pos = 0; 53 int new_pos = 0;
44 int sample_count; 54 int sample_count;
45 55 intptr_t param;
46 /* Generic codec initialisation */
47 ci->configure(DSP_SET_SAMPLE_DEPTH, TTA_OUTPUT_DEPTH - 1);
48 56
49next_track:
50 status = CODEC_OK;
51
52 if (codec_init()) 57 if (codec_init())
53 { 58 {
54 DEBUGF("codec_init() error\n"); 59 DEBUGF("codec_init() error\n");
55 status = CODEC_ERROR; 60 return CODEC_ERROR;
56 goto exit;
57 } 61 }
58 62
59 if (codec_wait_taginfo() != 0) 63 ci->seek_buffer(0);
60 goto done;
61 64
62 if (set_tta_info(&info) < 0 || player_init(&info) < 0) 65 if (set_tta_info(&info) < 0 || player_init(&info) < 0)
63 { 66 return CODEC_ERROR;
64 status = CODEC_ERROR;
65 goto exit;
66 }
67 67
68 codec_set_replaygain(ci->id3); 68 codec_set_replaygain(ci->id3);
69 69
@@ -74,8 +74,8 @@ next_track:
74 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); 74 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
75 } else { 75 } else {
76 DEBUGF("CODEC_ERROR: more than 2 channels\n"); 76 DEBUGF("CODEC_ERROR: more than 2 channels\n");
77 status = CODEC_ERROR; 77 player_stop();
78 goto done; 78 return CODEC_ERROR;
79 } 79 }
80 80
81 /* The main decoder loop */ 81 /* The main decoder loop */
@@ -88,31 +88,31 @@ next_track:
88 new_pos = set_position(ci->id3->offset, TTA_SEEK_POS); 88 new_pos = set_position(ci->id3->offset, TTA_SEEK_POS);
89 if (new_pos >= 0) 89 if (new_pos >= 0)
90 decodedsamples = new_pos; 90 decodedsamples = new_pos;
91 ci->seek_complete();
92 } 91 }
93 92
94 while (!endofstream) 93 while (!endofstream)
95 { 94 {
96 ci->yield(); 95 enum codec_command_action action = ci->get_command(&param);
97 if (ci->stop_codec || ci->new_track) 96
97 if (action == CODEC_ACTION_HALT)
98 break; 98 break;
99 99
100 if (ci->seek_time) 100 if (action == CODEC_ACTION_SEEK_TIME)
101 { 101 {
102 new_pos = set_position(ci->seek_time / SEEK_STEP, TTA_SEEK_TIME); 102 new_pos = set_position(param / SEEK_STEP, TTA_SEEK_TIME);
103 if (new_pos >= 0) 103 if (new_pos >= 0)
104 { 104 {
105 decodedsamples = new_pos; 105 decodedsamples = new_pos;
106 ci->seek_complete();
107 } 106 }
107
108 ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH);
109 ci->seek_complete();
108 } 110 }
109 111
110 sample_count = get_samples(samples); 112 sample_count = get_samples(samples);
111 if (sample_count < 0) 113 if (sample_count < 0)
112 {
113 status = CODEC_ERROR;
114 break; 114 break;
115 } 115
116 ci->pcmbuf_insert(samples, NULL, sample_count); 116 ci->pcmbuf_insert(samples, NULL, sample_count);
117 decodedsamples += sample_count; 117 decodedsamples += sample_count;
118 if (decodedsamples >= info.DATALENGTH) 118 if (decodedsamples >= info.DATALENGTH)
@@ -120,11 +120,6 @@ next_track:
120 ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH); 120 ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH);
121 } 121 }
122 122
123done:
124 player_stop(); 123 player_stop();
125 if (ci->request_next_track()) 124 return CODEC_OK;
126 goto next_track;
127
128exit:
129 return status;
130} 125}