Asterisk media

From 탱이의 잡동사니
Revision as of 08:00, 17 October 2018 by Pchero (talk | contribs) (→‎Caching)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Asterisk media caching 내용 정리.

Basic

Asterisk 에서는 Asterisk-13 에서 소개된 내용 중 하나는 Media 를 URI 로 받아서 바로 play 할 수 있는 내용이었다. 그리고, Asterisk-14 에서는 캐싱(Caching)까지 가능하도록 되었다.

하지만 몇가지 특징과 제한점이 있다.

Extension

Asterisk 에서는 파일의 Extension 을 이용하여 파일의 타입을 확인하지 않고, 파일을 열어서 직접 포멧을 확인하는 방식을 사용해 왔다. 하지만 URI 를 통해 Media 를 제공할 경우, 반드시 파일의 확장자(Extension)가 있어야 한다.

URI Scheme

HTTP 혹은 HTTPS 모두 지원이 가능하다.

Caching

Media(sound) 가 한번 전송이 되고나면 해당 내용은 local server 에 캐싱된다. 캐싱 및 캐싱된 이후의 관리는 전적으로 standard http 규칙을 따른다. 일반적으로 다음과 같이 작동한다.

  • If a Cache-Control header is included, Asterisk will obey whatever rules it specifies. In particular, the following should be checked.
If no-cache is specified, the resulting file is marked as always 'dirty' - that is, we have to always retrieve a new resource from the server.
If no-store is specified, Asterisk must attempt to purge the information before Asterisk shutdown and will always retrieve the resource from the server.
s-maxage or max-age : Mark the file as 'dirty' after so many seconds.
  • If the cached resource is 'dirty', look at the E-Tag header on the remote resource and compare it to the local E-Tag. If the two are different, retrieve the resource and update the entry in the cache. If the cached resource was retrieved with no-store, then we always retrieve the full resource.

일단 캐싱요청이 들어오면 파일을 다운로드(curl lib 를 사용한다)한 후

요청하는 내용과 캐싱된 내용이 같은 내용인지 아닌지를 판별하는 방법은 제공된 URI 와 캐싱된 미디어의 URI 를 비교하여 확인한다. <source lang=c> /* First, retrieve from the ao2 cache here. If we find a bucket_file * matching the requested URI, ask the appropriate backend if it is * stale. If not; return it. */ bucket_file = ao2_find(media_cache, uri, OBJ_SEARCH_KEY | OBJ_NOLOCK); if (bucket_file) { if (!ast_bucket_file_is_stale(bucket_file) && ast_file_is_readable(bucket_file->path)) { ast_copy_string(file_path, bucket_file->path, len); if ((ext = strrchr(file_path, '.'))) { *ext = '\0'; } ao2_ref(bucket_file, -1);

ast_debug(5, "Returning media at local file: %s\n", file_path); return 0; }

/* Stale! Remove the item completely, as we're going to replace it next */ ao2_unlink_flags(media_cache, bucket_file, OBJ_NOLOCK); ast_bucket_file_delete(bucket_file); ao2_ref(bucket_file, -1); } </source>

See also