<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/file_path.h"
#include "mojo/common/data_pipe_utils.h"
#include "sky/services/media/ios/media_player_impl.h"

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface AudioClient : NSObject

- (instancetype)initWithPath:(NSString*)path;

- (BOOL)play;
- (void)pause;
- (BOOL)seekTo:(NSTimeInterval)interval;

+ (NSString*)temporaryFilePath;

@end

@implementation AudioClient {
  AVAudioPlayer* _player;
}

- (instancetype)initWithPath:(NSString*)path {
  self = [super init];

  if (self) {
    NSError* error = nil;
    _player =
        [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path]
                                               error:&error];

    if (error != nil) {
      NSLog(@"Could not initialize audio client: %@",
            error.localizedDescription);
      [self release];
      return nil;
    }
  }

  return self;
}

- (BOOL)play {
  return [_player play];
}

- (void)pause {
  [_player pause];
}

- (BOOL)seekTo:(NSTimeInterval)interval {
  return [_player playAtTime:_player.deviceCurrentTime + interval];
}

+ (NSString*)temporaryFilePath {
  char* path = reinterpret_cast<char*>(calloc(256, sizeof(char)));

  snprintf(path, 256, "%smedia.XXXXXX", NSTemporaryDirectory().UTF8String);
  path = mktemp(path);

  if (path == NULL) {
    free(path);
    return NULL;
  }

  NSString* pathString = [NSString stringWithUTF8String:path];
  free(path);

  return pathString;<commit_msg>Avoid using malloc/free when trying to calculate the temporary file directory<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/file_path.h"
#include "mojo/common/data_pipe_utils.h"
#include "sky/services/media/ios/media_player_impl.h"

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface AudioClient : NSObject

- (instancetype)initWithPath:(NSString*)path;

- (BOOL)play;
- (void)pause;
- (BOOL)seekTo:(NSTimeInterval)interval;

+ (NSString*)temporaryFilePath;

@end

@implementation AudioClient {
  AVAudioPlayer* _player;
}

- (instancetype)initWithPath:(NSString*)path {
  self = [super init];

  if (self) {
    NSError* error = nil;
    _player =
        [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path]
                                               error:&error];

    if (error != nil) {
      NSLog(@"Could not initialize audio client: %@",
            error.localizedDescription);
      [self release];
      return nil;
    }
  }

  return self;
}

- (BOOL)play {
  return [_player play];
}

- (void)pause {
  [_player pause];
}

- (BOOL)seekTo:(NSTimeInterval)interval {
  return [_player playAtTime:_player.deviceCurrentTime + interval];
}

+ (NSString*)temporaryFilePath {
  char temp[256] = {0};

  snprintf(temp, sizeof(temp), "%smedia.XXXXXX", NSTemporaryDirectory().UTF8String);
  char *path = mktemp(temp);

  if (path == NULL) {
    return NULL;
  }

  return [NSString stringWithUTF8String:path];
{'fraction_non_alphanumeric': 0.12926829268292683, 'fraction_numerical': 0.006707317073170732, 'mean_word_length': 3.653900709219858, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814089', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1025, 'n_words': 238}