Fix log msg
[platform/core/multimedia/libmedia-thumbnail.git] / src / ipc / media-thumb-ipc.c
1 /*
2  * libmedia-thumbnail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "media-thumbnail.h"
23 #include "media-thumb-ipc.h"
24 #include "media-thumb-util.h"
25 #include "media-thumb-db.h"
26 #include "media-thumb-debug.h"
27 #include <glib.h>
28 #include <fcntl.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <grp.h>
32 #include <pwd.h>
33
34 #define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket")
35
36 static GQueue *g_manage_queue = NULL;
37 static GQueue *g_manage_raw_queue = NULL;
38
39
40 typedef struct {
41         GIOChannel *channel;
42         int msg_type;
43         unsigned int request_id;
44         bool isCanceled;
45         bool isRequested;
46         int source_id;
47         uid_t uid;
48         char *path;
49         thumbUserData *userData;
50 } thumbReq;
51
52 typedef struct {
53         GIOChannel *channel;
54         int msg_type;
55         bool isCanceled;
56         bool isRequested;
57         int request_id;
58         int source_id;
59         int width;
60         int height;
61         uid_t uid;
62         char *path;
63         thumbRawUserData *userData;
64 } thumbRawReq;
65
66 static int _media_thumb_send_request();
67 static int _media_thumb_raw_data_send_request();
68
69
70 int _media_thumb_get_error()
71 {
72         if (errno == EWOULDBLOCK) {
73                 thumb_err("Timeout. Can't try any more");
74                 return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
75         } else {
76                 thumb_stderror("recvfrom failed");
77                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
78         }
79 }
80
81 void __media_thumb_pop()
82 {
83         int len = 0;
84
85         if (g_manage_queue != NULL) {
86                 thumbReq *req = (thumbReq *)g_queue_pop_head(g_manage_queue);
87                 if (req != NULL) {
88                         GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
89
90                         g_io_channel_shutdown(req->channel, TRUE, NULL);
91                         g_io_channel_unref(req->channel);
92
93                         if (source_id != NULL) {
94                                 g_source_destroy(source_id);
95                         } else {
96                                 thumb_err("G_SOURCE_ID is NULL");
97                         }
98
99                         SAFE_FREE(req->path);
100                         SAFE_FREE(req->userData);
101                         SAFE_FREE(req);
102                 }
103
104                 /* Check manage queue */
105                 len = g_queue_get_length(g_manage_queue);
106                 if (len > 0)
107                         _media_thumb_send_request();
108         }
109 }
110
111 int __media_thumb_cancel(unsigned int request_id)
112 {
113         int len = 0, i;
114         bool flag = false;
115
116         if (g_manage_queue != NULL) {
117                 len = g_queue_get_length(g_manage_queue);
118
119                 for (i = 0; i < len; i++) {
120                         thumbReq *req = NULL;
121                         req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
122                         if (req == NULL) continue;
123
124                         if (req->request_id == request_id) {
125                                 if (req->isRequested == true) {
126                                         req->isCanceled = true;
127                                 } else {
128                                         g_queue_pop_nth(g_manage_queue, i);
129
130                                         SAFE_FREE(req->path);
131                                         SAFE_FREE(req->userData);
132                                         SAFE_FREE(req);
133                                 }
134
135                                 flag = true;
136
137                                 break;
138                         }
139                 }
140         }
141
142         if (flag == false)
143                 return MS_MEDIA_ERR_INTERNAL;
144
145         return MS_MEDIA_ERR_NONE;
146 }
147
148 void __media_thumb_pop_raw_data()
149 {
150         int len = 0;
151
152         if (g_manage_raw_queue != NULL) {
153                 thumbRawReq *req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
154                 if (req != NULL) {
155                         GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
156
157                         g_io_channel_shutdown(req->channel, TRUE, NULL);
158                         g_io_channel_unref(req->channel);
159
160                         if (source_id != NULL) {
161                                 g_source_destroy(source_id);
162                         } else {
163                                 thumb_err("G_SOURCE_ID is NULL");
164                         }
165
166                         SAFE_FREE(req->path);
167                         SAFE_FREE(req->userData);
168                         SAFE_FREE(req);
169                 }
170
171                 /* Check manage queue */
172                 len = g_queue_get_length(g_manage_raw_queue);
173                 if (len > 0)
174                         _media_thumb_raw_data_send_request();
175         }
176 }
177
178 int __media_thumb_cancel_raw_data(int request_id)
179 {
180         int len = 0, i;
181         bool flag = false;
182
183         if (g_manage_raw_queue != NULL) {
184                 len = g_queue_get_length(g_manage_raw_queue);
185
186                 for (i = 0; i < len; i++) {
187                         thumbRawReq *req = NULL;
188                         req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
189                         if (req == NULL) continue;
190
191                         if (req->request_id == request_id) {
192                                 if (req->isRequested == true) {
193                                         req->isCanceled = true;
194                                 } else {
195                                         g_queue_pop_nth(g_manage_raw_queue, i);
196
197                                         SAFE_FREE(req->path);
198                                         SAFE_FREE(req->userData);
199                                         SAFE_FREE(req);
200                                 }
201
202                                 flag = true;
203
204                                 break;
205                         }
206                 }
207         }
208
209         if (flag == false)
210                 return MS_MEDIA_ERR_INTERNAL;
211
212         return MS_MEDIA_ERR_NONE;
213
214 }
215
216 bool __media_thumb_check_cancel(void)
217 {
218         thumbReq *req = NULL;
219         req = (thumbReq *)g_queue_peek_head(g_manage_queue);
220
221         if (req == NULL) {
222                 return false;
223         } else {
224                 if (req->isCanceled)
225                         return false;
226                 else
227                         return true;
228         }
229 }
230
231 bool __media_thumb_check_cancel_for_raw(void)
232 {
233         thumbRawReq *req = NULL;
234         req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
235
236         if (req == NULL) {
237                 return false;
238         } else {
239                 if (req->isCanceled)
240                         return false;
241                 else
242                         return true;
243         }
244 }
245
246 int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
247 {
248         int remain_size = 0;
249         unsigned char *buf = NULL;
250
251         THUMB_MALLOC(buf, header_size);
252         if (buf == NULL) {
253                 thumb_err("memory allocation failed");
254                 SAFE_FREE(buf);
255                 return MS_MEDIA_ERR_OUT_OF_MEMORY;
256         }
257
258         if (recv(sock, buf, header_size, 0) < 0) {
259                 thumb_stderror("recv failed");
260                 SAFE_FREE(buf);
261                 return _media_thumb_get_error();
262         }
263
264         memcpy(msg, buf, header_size);
265
266         if (strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MAX_FILEPATH_LEN) {
267                 thumb_err("org_path size is invalid %d", strlen(msg->org_path));
268
269                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
270         }
271
272         /* it can be empty string */
273         if (strlen(msg->dst_path) >= MAX_FILEPATH_LEN) {
274                 thumb_err("dst_path size is invalid %d", strlen(msg->dst_path));
275
276                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
277         }
278
279         SAFE_FREE(buf);
280         if (msg->thumb_size < 0) {
281                 thumb_err("recv data is wrong");
282                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
283         }
284
285         if (msg->thumb_size > 0) {
286                 remain_size = msg->thumb_size;
287                 THUMB_MALLOC(buf, remain_size);
288                 if (buf == NULL)
289                         return MS_MEDIA_ERR_OUT_OF_MEMORY;
290
291                 if (recv(sock, buf, remain_size, 0) < 0) {
292                         thumb_stderror("recv failed");
293                         SAFE_FREE(buf);
294                         return _media_thumb_get_error();
295                 }
296
297                 SAFE_FREE(msg->thumb_data);
298                 THUMB_MALLOC(msg->thumb_data, msg->thumb_size);
299                 if (msg->thumb_data != NULL) {
300                         memcpy(msg->thumb_data, buf, msg->thumb_size);
301                 } else {
302                         SAFE_FREE(buf);
303
304                         return MS_MEDIA_ERR_OUT_OF_MEMORY;
305                 }
306         }
307
308         SAFE_FREE(buf);
309
310         return MS_MEDIA_ERR_NONE;
311 }
312
313 int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
314 {
315         if (req_msg == NULL || buf == NULL)
316                 return MS_MEDIA_ERR_INVALID_PARAMETER;
317
318         int thumb_data_len = 0;
319         int size = 0;
320         int header_size = 0;
321
322         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
323         thumb_data_len = req_msg->thumb_size;
324         if (thumb_data_len < 0)
325                 return MS_MEDIA_ERR_INVALID_PARAMETER;
326
327         //thumb_dbg("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data_len[%d]", header_size, req_msg->org_path, req_msg->dst_path, thumb_data_len);
328
329         size = header_size + thumb_data_len;
330         THUMB_MALLOC(*buf, size);
331         if (*buf == NULL) {
332                 *buf_size = 0;
333                 return 0;
334         }
335         memcpy(*buf, req_msg, header_size);
336         if (thumb_data_len > 0)
337                 memcpy((*buf) + header_size, req_msg->thumb_data, thumb_data_len);
338
339         *buf_size = size;
340
341         return MS_MEDIA_ERR_NONE;
342 }
343
344 gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
345 {
346         thumbMsg recv_msg;
347         int header_size = 0;
348         int sock = 0;
349         int err = MS_MEDIA_ERR_NONE;
350
351         memset((void *)&recv_msg, 0, sizeof(thumbMsg));
352         sock = g_io_channel_unix_get_fd(src);
353
354         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
355
356         thumb_err("_media_thumb_write_socket socket : %d", sock);
357
358         if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
359                 thumb_err("_media_thumb_recv_msg failed ");
360                 __media_thumb_pop();
361
362                 return FALSE;
363         }
364
365         if (recv_msg.status != MS_MEDIA_ERR_NONE) {
366                 err = recv_msg.status;
367                 thumb_err("Failed to make thumbnail (%d)", err);
368         }
369
370         if (__media_thumb_check_cancel()) {
371                 if (data) {
372                         thumbUserData* cb = (thumbUserData*)data;
373                         if (cb->func != NULL)
374                                 cb->func(err, recv_msg.dst_path, cb->user_data);
375                 }
376         }
377
378         __media_thumb_pop();
379
380         thumb_dbg("Done");
381
382         return FALSE;
383 }
384
385 gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
386 {
387         thumbMsg recv_msg;
388         int header_size = 0;
389         int sock = 0;
390         int err = MS_MEDIA_ERR_NONE;
391
392         memset((void *)&recv_msg, 0, sizeof(thumbMsg));
393         sock = g_io_channel_unix_get_fd(src);
394
395         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
396
397         thumb_err("_media_thumb_write_socket socket : %d", sock);
398
399         if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
400                 thumb_err("_media_thumb_recv_msg failed ");
401                 __media_thumb_pop_raw_data();
402
403                 return FALSE;
404         }
405
406         if (recv_msg.status != MS_MEDIA_ERR_NONE) {
407                 err = recv_msg.status;
408                 thumb_err("Failed to make thumbnail (%d)", err);
409         }
410
411         if (__media_thumb_check_cancel_for_raw()) {
412                 if (data) {
413                         thumbRawUserData* cb = (thumbRawUserData*)data;
414                         if (cb->func != NULL)
415                                 cb->func(err, recv_msg.request_id, recv_msg.org_path, recv_msg.thumb_width, recv_msg.thumb_height, recv_msg.thumb_data, recv_msg.thumb_size, cb->user_data);
416                 }
417         }
418
419         __media_thumb_pop_raw_data();
420
421         thumb_dbg("Done");
422
423         return FALSE;
424 }
425
426 static int _media_thumb_send_request()
427 {
428         int err = MS_MEDIA_ERR_NONE;
429         int sock = -1;
430         struct sockaddr_un serv_addr;
431         thumbReq *req_manager = NULL;
432         int pid;
433
434         err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
435         if (err != MS_MEDIA_ERR_NONE) {
436                 thumb_err("ms_ipc_create_client_socket failed");
437                 return err;
438         }
439
440         memset(&serv_addr, 0, sizeof(serv_addr));
441         serv_addr.sun_family = AF_UNIX;
442         SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
443
444         GIOChannel *channel = NULL;
445         channel = g_io_channel_unix_new(sock);
446         int source_id = -1;
447
448         /* Connecting to the thumbnail server */
449         if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
450                 thumb_stderror("connect");
451                 if (errno == EACCES)
452                         err = MS_MEDIA_ERR_PERMISSION_DENIED;
453                 else
454                         err = MS_MEDIA_ERR_SOCKET_CONN;
455
456                 g_io_channel_shutdown(channel, TRUE, NULL);
457                 g_io_channel_unref(channel);
458                 close(sock);
459
460                 return err;
461         }
462
463         req_manager = (thumbReq *)g_queue_peek_head(g_manage_queue);
464
465         if (req_manager == NULL) {
466                 thumb_err("queue peek fail");
467                 g_io_channel_shutdown(channel, TRUE, NULL);
468                 g_io_channel_unref(channel);
469                 close(sock);
470                 return MS_MEDIA_ERR_INVALID_PARAMETER;
471         }
472
473         GSource *source = NULL;
474         source = g_io_create_watch(channel, G_IO_IN);
475         g_source_set_callback(source, (GSourceFunc)_media_thumb_write_socket, req_manager->userData, NULL);
476         source_id = g_source_attach(source, g_main_context_get_thread_default());
477
478         thumbMsg req_msg;
479         memset((void *)&req_msg, 0, sizeof(thumbMsg));
480
481         pid = getpid();
482         req_msg.pid = pid;
483         req_msg.msg_type = req_manager->msg_type;
484         req_msg.request_id = 0;
485         req_msg.uid = req_manager->uid;
486         SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
487         req_msg.dst_path[0] = '\0';
488         req_msg.thumb_size = 0;
489
490         unsigned char *buf = NULL;
491         int buf_size = 0;
492         _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
493
494         if (send(sock, buf, buf_size, 0) < 0) {
495                 thumb_err("send failed: %d", errno);
496                 SAFE_FREE(buf);
497                 g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
498                 g_io_channel_shutdown(channel, TRUE, NULL);
499                 g_io_channel_unref(channel);
500                 close(sock);
501                 return MS_MEDIA_ERR_SOCKET_SEND;
502         }
503
504         SAFE_FREE(buf);
505         thumb_dbg("Sending msg to thumbnail daemon is successful");
506
507         if (req_manager->msg_type == THUMB_REQUEST_DB_INSERT) {
508                 req_manager->channel = channel;
509                 req_manager->source_id = source_id;
510                 req_manager->isRequested = true;
511         }
512
513         return err;
514 }
515
516 static int _media_thumb_raw_data_send_request()
517 {
518         int err = MS_MEDIA_ERR_NONE;
519         int sock = -1;
520         struct sockaddr_un serv_addr;
521         thumbRawReq *req_manager = NULL;
522         int pid;
523
524         err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
525         if (err != MS_MEDIA_ERR_NONE) {
526                 thumb_err("ms_ipc_create_client_socket failed");
527                 return err;
528         }
529
530         memset(&serv_addr, 0, sizeof(serv_addr));
531         serv_addr.sun_family = AF_UNIX;
532         SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
533
534         GIOChannel *channel = NULL;
535         channel = g_io_channel_unix_new(sock);
536         int source_id = -1;
537
538         /* Connecting to the thumbnail server */
539         if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
540                 thumb_stderror("connect error");
541                 if (errno == EACCES)
542                         err = MS_MEDIA_ERR_PERMISSION_DENIED;
543                 else
544                         err = MS_MEDIA_ERR_SOCKET_CONN;
545
546                 g_io_channel_shutdown(channel, TRUE, NULL);
547                 g_io_channel_unref(channel);
548                 close(sock);
549                 return err;
550         }
551
552         req_manager = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
553
554         if (req_manager == NULL) {
555                 thumb_err("queue peek fail");
556                 g_io_channel_shutdown(channel, TRUE, NULL);
557                 g_io_channel_unref(channel);
558                 close(sock);
559                 return MS_MEDIA_ERR_INVALID_PARAMETER;
560         }
561
562         GSource *source = NULL;
563         source = g_io_create_watch(channel, G_IO_IN);
564         g_source_set_callback(source, (GSourceFunc)_media_thumb_raw_data_write_socket, req_manager->userData, NULL);
565         source_id = g_source_attach(source, g_main_context_get_thread_default());
566
567         thumbMsg req_msg;
568         memset((void *)&req_msg, 0, sizeof(thumbMsg));
569
570         pid = getpid();
571         req_msg.pid = pid;
572         req_msg.msg_type = req_manager->msg_type;
573         req_msg.request_id = req_manager->request_id;
574         req_msg.thumb_width = req_manager->width;
575         req_msg.thumb_height = req_manager->height;
576         req_msg.uid = req_manager->uid;
577
578         SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
579         req_msg.dst_path[0] = '\0';
580         req_msg.thumb_size = 0;
581
582         unsigned char *buf = NULL;
583         int buf_size = 0;
584         _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
585
586         if (send(sock, buf, buf_size, 0) < 0) {
587                 thumb_err("send failed: %d", errno);
588                 SAFE_FREE(buf);
589                 g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
590                 g_io_channel_shutdown(channel, TRUE, NULL);
591                 g_io_channel_unref(channel);
592                 return MS_MEDIA_ERR_SOCKET_SEND;
593         }
594
595         SAFE_FREE(buf);
596
597         if (req_manager->msg_type == THUMB_REQUEST_RAW_DATA) {
598                 req_manager->channel = channel;
599                 req_manager->source_id = source_id;
600                 req_manager->isRequested = true;
601         }
602         return MS_MEDIA_ERR_NONE;
603 }
604
605 int _media_thumb_request_async(int msg_type, unsigned int request_id, const char *origin_path, thumbUserData *userData, uid_t uid)
606 {
607         int err = MS_MEDIA_ERR_NONE;
608         int len = 0;
609
610         if (msg_type == THUMB_REQUEST_CANCEL_MEDIA)
611                 return __media_thumb_cancel(request_id);
612
613         if (g_manage_queue == NULL)
614                 g_manage_queue = g_queue_new();
615
616         thumbReq *thumb_req = NULL;
617         THUMB_MALLOC(thumb_req, sizeof(thumbReq));
618         thumb_retvm_if(thumb_req == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Failed to create request element");
619
620         thumb_req->msg_type = msg_type;
621         thumb_req->path = g_strdup(origin_path);
622         thumb_req->userData = userData;
623         thumb_req->isCanceled = false;
624         thumb_req->isRequested = false;
625         thumb_req->request_id = request_id;
626         thumb_req->uid = uid;
627
628         len = g_queue_get_length(g_manage_queue);
629         g_queue_push_tail(g_manage_queue, (gpointer)thumb_req);
630
631         if (len == 0)
632                 err = _media_thumb_send_request();
633
634         return err;
635 }
636
637 int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char *origin_path, int width, int height, thumbRawUserData *userData, uid_t uid)
638 {
639         int err = MS_MEDIA_ERR_NONE;
640         int len = 0;
641         thumbRawReq *thumb_req = NULL;
642
643         if (msg_type == THUMB_REQUEST_CANCEL_RAW_DATA)
644                 return __media_thumb_cancel_raw_data(request_id);
645
646         if (g_manage_raw_queue == NULL)
647                 g_manage_raw_queue = g_queue_new();
648
649         THUMB_MALLOC(thumb_req, sizeof(thumbRawReq));
650         if (thumb_req == NULL) {
651                 thumb_err("Failed to create request element");
652                 return MS_MEDIA_ERR_INVALID_PARAMETER;
653         }
654
655         thumb_req->msg_type = msg_type;
656         thumb_req->request_id = request_id;
657         thumb_req->path = g_strdup(origin_path);
658         thumb_req->width = width;
659         thumb_req->height = height;
660         thumb_req->userData = userData;
661         thumb_req->isCanceled = false;
662         thumb_req->isRequested = false;
663         thumb_req->uid = uid;
664
665         len = g_queue_get_length(g_manage_raw_queue);
666         g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req);
667
668         if (len == 0)
669                 err = _media_thumb_raw_data_send_request();
670
671         return err;
672 }
673
674 int _media_thumb_request_cancel_all()
675 {
676         if (g_manage_raw_queue != NULL) {
677                 while (g_queue_get_length(g_manage_raw_queue) > 0) {
678                         thumbRawReq *req = (thumbRawReq *)g_queue_peek_tail(g_manage_raw_queue);
679                         if (req != NULL) {
680                                 if (req->isRequested == true) {
681                                         req->isCanceled = true;
682                                         thumb_dbg("Last item!!");
683
684                                         break;
685                                 } else {
686                                         g_queue_pop_tail(g_manage_raw_queue);
687
688                                         SAFE_FREE(req->path);
689                                         SAFE_FREE(req->userData);
690                                         SAFE_FREE(req);
691                                 }
692                         } else {
693                                 thumb_dbg("Queue is empty!!");
694                                 break;
695                         }
696                 }
697         }
698
699         return MS_MEDIA_ERR_NONE;
700 }